2015-12-18 41 views
0

不可見我增加了圓形的UIButton是這樣的:當按鈕被顯示文本在圓的UIButton的iOS

-(void)addInfoButton 
{ 
    UIButton *pButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

    [pButton addTarget:self 
       action:@selector(infoButtonDidTap:) 
     forControlEvents:UIControlEventTouchUpInside]; 

    pButton.frame = [self getInfoButtonFrame]; 

    pButton.clipsToBounds = NO; 

    //half of the width 
    pButton.layer.cornerRadius = BUTTON_HEIGHT/2.0f; 
    pButton.layer.borderColor = self.tintColor.CGColor; 
    pButton.layer.borderWidth = 2.0f; 

    pButton.titleLabel.text = @"F"; 

    pButton.titleLabel.textColor = self.tintColor; 
    pButton.titleLabel.textAlignment = NSTextAlignmentCenter; 

    self.filterInfoButton = pButton; 

    [self addSubview:pButton]; 
} 

文本「F」是不可見的。可能是什麼原因?

編輯: 將角半徑設置爲0時,文字可見。但是,那麼按鈕不是圓形的。

+0

你能看到按鈕嗎?按鈕框是什麼? –

+0

是的,我可以完全看到按鈕..按鈕的高度和寬度是每個44 – StudentX

+1

「可能是什麼原因?」各種各樣的東西 - 例如,你試圖用什麼顏色來表現文字顏色? – TwoStraws

回答

1

您使用

- setTitle:forState: 

設置標題使用指定狀態設置一個UIButton的標題。

使用屬性titleLabel不會設置用於自定義按鈕標題標籤的文本。

titleLabel 

顯示的currentTitle屬性爲一個按鈕的值的圖。 (只讀)儘管此屬性是隻讀的,但它自己的屬性是可讀/寫的。主要使用這些屬性來配置按鈕的文本。例如:

button.titleLabel.font = UIFont.systemFontOfSize(12)