iPhone UIButton圖標與文字間距設置【轉】

 UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 150, 50)];

    [button setTitle:@"HHH" forState:UIControlStateNormal];

    [button setBackgroundImage:[UIImage imageNamed:@"narrowend.png"] forState:UIControlStateNormal];

    [button setImage:[UIImage imageNamed:@"panelicon.png"] forState:UIControlStateNormal];   

默認情況下,圖片及按鈕文字如下:

 iPhone UIButton圖標與文字間距設置【轉】 - 逍遙十四少 - 逍遙十四少

加入如下代碼後

 [button setImageEdgeInsets:UIEdgeInsetsMake(0.0, -20, 0.0, 0.0)];

iPhone UIButton圖標與文字間距設置【轉】 - 逍遙十四少 - 逍遙十四少

[button setImageEdgeInsets:UIEdgeInsetsMake(<#CGFloat top#向上偏移量>, <#CGFloat left#向左偏移量>, <#CGFloat bottom#向下偏移量>, <#CGFloat right#向右上偏移量>)];
同時還可以設置文字的偏移量:

[button setTitleEdgeInsets:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章