1
如果我在IB中創建了一個按鈕,並且只將類型設置爲自定義,標題和字體大小,它會很好,清晰。如果我通過編程創建它,那麼字體會變得模糊。創建按鈕的代碼是:iOS自定義按鈕標題模糊
CGRect frame = self.sendButton.frame;
NSString *title = @"Read Disclosure";
UIFont *font = [UIFont boldSystemFontOfSize:17.0];
CGSize titleSize = [title sizeWithFont:font constrainedToSize:frame.size];
CGFloat xValue = (self.view.frame.size.width - titleSize.width)/2;
CGFloat yValue = frame.origin.y - (titleSize.height/2);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(xValue, yValue, titleSize.width, titleSize.height * 2)];
[button setTitle:@"Read Disclosure" forState:UIControlStateNormal];
[button.titleLabel setFont:font];
[button setTitleColor:[UIColor colorWithRed:50.0/255.0 green:79.0/255.0 blue:133.0/255.0 alpha:1.0] forState:UIControlStateNormal];
[button setTitleShadowColor:nil forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(disclosureButtonAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
我試過了所有我能想到的設置,沒有任何東西似乎有所作爲。任何想法我在這裏失蹤?
謝謝。
是的,就是這樣。我以爲我已經檢查過這些,但我猜不是。謝謝! – mickm
歡迎來到Stack Overflow!請記住標記正確答案爲已接受。 –
謝謝!我如何標記它,以下是「此帖是否有用......」按鈕? – mickm