[英]-[UITextView setAttributedText:] stops working, when I use UITraitCollection variations
[英]setAttributedText is not working on UIButton?
我試圖在UIButton上設置屬性字符串標題,但它似乎不起作用。
[self.emailSignInButton.titleLabel setAttributedText:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"LOGIN_WITH_EMAIL", nil) attributes:@{ NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)}]];
雖然這完全正常。
[self.emailSignInButton.titleLabel setText:NSLocalizedString(@"LOGIN_WITH_EMAIL", nil)];
奇怪的是另一個按鈕文本與屬性文本很好。 例如。
[self.emailSignupButton.titleLabel setAttributedText:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"CREATE_ACCOUNT_WITH_EMAIL", nil) attributes:@{ NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)}]]`;
知道這里發生了什么嗎?
您需要設置按鈕狀態的文本。 UIButton可以有幾種不同的狀態。
您很可能需要Normal ,這將為所有情況設置默認標題。
的UIButton
- setAttributedTitle:forState:
設置要用於指定狀態的樣式標題。
以下是您的代碼示例
NSAttributedString *string = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"LOGIN_WITH_EMAIL", nil)
attributes:@{ NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)}]
[self.emailSignInButton setAttributedTitle:string forState:UIControlStateNormal];
引用:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.