gpt4 book ai didi

ios - UISegmentedControl setTitleTextAttributes 不起作用

转载 作者:可可西里 更新时间:2023-11-01 03:24:16 24 4
gpt4 key购买 nike

所以我尝试更改我的 UISegmentedControl 标题的文本属性,但它不起作用,没有任何变化。我还应用了自定义背景和分隔线,它可以正常工作,但不是这个。

NSDictionary *normaltextAttr = 
@{[UIColor blackColor]: UITextAttributeTextColor,
[UIColor clearColor]: UITextAttributeTextShadowColor,
[UIFont fontWithName:_regularFont size:20.f]: UITextAttributeFont};


NSDictionary *selectedtextAttr =
@{[UIColor colorWithRed:135.0/255.0 green:135.0/255.0 blue:135.0/255.0 alpha:1.0]: UITextAttributeTextColor,
[UIColor clearColor]: UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)]: UITextAttributeTextShadowOffset,
[UIFont fontWithName:_regularFont size:0.0]: UITextAttributeFont};

[[UISegmentedControl appearance] setTitleTextAttributes:normaltextAttr
forState:UIControlStateNormal];
[[UISegmentedControl appearance] setTitleTextAttributes:selectedtextAttr
forState:UIControlStateSelected];

最佳答案

请注意工厂方法(/)之间排序方式的差异

[NSDictionary dictionaryWithObjectsAndKeys: value, key, nil]

和文字声明(key/value)

@{key: value}

您只是使用了错误的键和值顺序。

这将起作用:

NSDictionary *normaltextAttr = 
@{UITextAttributeTextColor : [UIColor blackColor],
UITextAttributeTextShadowColor : [UIColor clearColor],
UITextAttributeFont : [UIFont fontWithName:_regularFont size:20.f]};


[[UISegmentedControl appearance] setTitleTextAttributes:normaltextAttr forState:UIControlStateNormal];

关于ios - UISegmentedControl setTitleTextAttributes 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18464902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com