我是UIButton的子類設置應用程序的一些默認值,但我出於某種原因,我無法更改字體大小。UIButton的子類化和設置fontSize
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// id button, set defaults
[self setTintColor:[UIColor blueColor]];
[self.titleLabel setFont:[UIFont systemFontOfSize:40.0]];
[self.layer setBorderWidth:1.0f];
[self.layer setBorderColor:[[UIColor blackColor] CGColor]];
}
return self;
}
我可以改變顏色和其他特性,但不是字體大小,它沒有效果?
idButton *LButton = [idButton buttonWithType:UIButtonTypeRoundedRect];
[LButton setTitle:@"Login" forState:UIControlStateNormal];
LButton.frame = CGRectMake(0, buttonY+(buttonHeight/2), screenWidth, buttonHeight);
[self addSubview:LButton];
嘗試在更改屬性後調用'[self setNeedsDisplay]'。 – 68cherries
你是否調用initWithFrame按鈕,或者它是否正在使用另一個init函數實例化,如故事板(initWithCoder) – Jbryson
我正在使用mySubClass * Button = [mySubClass buttonWithType:UIButtonTypeRoundedRect];設置一個標題並將其添加爲另一個視圖中的子視圖 –