[英]UIButton with Text Stroke/Outline
我想繪制一個使用輪廓即筆觸的文本的UIButton
。 因此,我嘗試使用titleLabel制作自己的自定義標簽並分配給無效的UIButton.titleLabel
。 有人提到我可以在UIButton
頂部添加UILabel
,但我不確定此解決方案是否很好。
有人可以推薦一種穩定的方法來解決此問題嗎? 謝謝。
您可以使用
- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state
UIButton
方法。
例如。 像這樣的屬性字符串
NSAttributedString *attributedText =
[[NSAttributedString alloc] initWithString:title
attributes:@{NSStrokeWidthAttributeName: [NSNumber numberWithInt:-6],
NSStrokeColorAttributeName: titleBorderColor,
NSForegroundColorAttributeName: [UIColor whiteColor]}];
您也可以將視圖作為子視圖添加到按鈕。 在此視圖中,您可以放置標簽,或者,如果需要,可以放置更多標簽,例如具有兩個帶有不同格式文本行的按鈕。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.