如何更改UISegmentcontrol字体和选中段的颜色?

9

可能是重复问题:
UISegmentedControl选定的段颜色
UISegmentcontrol外观引起的问题

嗨,我想将默认的UISegmentControl字体更改为自定义字体,并将选定的段颜色更改为另一种颜色而不是较暗的颜色。

谢谢

从这里

enter image description here

到这里

enter image description here

编辑:解决方案 被称为

//更改字体大小,去除阴影,所选文本和背景颜色与正常状态不同

-(void)defineSegmentControlStyle
    {
        //normal segment
        NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont,
                                    [UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor, 
                                    [UIColor clearColor], UITextAttributeTextShadowColor,
                                    [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
                                    nil];//[NSDictionary dictionaryWithObject:  [UIColor redColor]forKey:UITextAttributeTextColor];
        [infoSegment setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];

        NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                          [UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont,
                                          [UIColor whiteColor], UITextAttributeTextColor, 
                                          [UIColor clearColor], UITextAttributeTextShadowColor,
                                          [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
                                          nil] ;//[NSDictionary dictionaryWithObject:  [UIColor redColor]forKey:UITextAttributeTextColor];
        [infoSegment setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];

    }

https://dev59.com/3nE95IYBdhLWcg3wi-Uc#5932524 - Robert Harvey
1个回答

1

谢谢回复,我看到了,但是我还需要设置自定义字体... - Desmond
也许这个链接可以帮到你:http://www.iphonedevsdk.com/forum/iphone-sdk-development/5059-change-font-size-text-uisegmentedcontrol.html - Jayson Lane
能否在UISegmentedControl中将选择的段落的字体大小与未选择的段落不同?我可以改变所选段落的颜色,但不能改变字体大小。 - Shreyas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接