UIButton with Text Stroke/Outline
问题描述:
我想绘制一个UIButoon
,其文字使用大纲即笔画。所以我试图用titleLabel来制作我自己的自定义标签,并指定UIButton.titleLabel
这是行不通的。有人提到我可以在UIButton
之上加UILabel
,但我不确定这个解决方案是否好。UIButton with Text Stroke/Outline
有人可以推荐一个稳定的方法来解决这个问题吗?谢谢。
答
你也可以添加一个视图作为子视图到你的按钮。 在此视图中,您可以放置标签,或者如果需要,可以放置更多标签,例如一个带有两个不同格式化文本行的按钮。
答
您可以使用UIButton
- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state
方法。
例如。像这样的属性串
NSAttributedString *attributedText =
[[NSAttributedString alloc] initWithString:title
attributes:@{NSStrokeWidthAttributeName: [NSNumber numberWithInt:-6],
NSStrokeColorAttributeName: titleBorderColor,
NSForegroundColorAttributeName: [UIColor whiteColor]}];
这可能不是最好的解决办法,但我想iOS 5的支持,所以不能使用答案与NSAttributedString,我也遇到了麻烦subclasssing的UIButton。 UILable我可以细分,它适用于我。 – Vad 2013-03-30 02:05:50