ios - uibutton image on the left and text on the center -
i creating button image on left , text on center. works somehow background color of red doesn't cover entire button.
self.buybutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; [self.buybutton.titlelabel setbackgroundcolor:[uicolor buttonred]]; uiimage *image = [uiimage imagenamed:@"cart.png"]; [self.buybutton setimage:image forstate:uicontrolstatenormal]; self.buybutton.imageedgeinsets = uiedgeinsetsmake(0, 10, 0, 0); [self.buybutton settitle:@"buy" forstate:uicontrolstatenormal]; self.buybutton.titleedgeinsets = uiedgeinsetsmake(0, 20, 0, 0); self.buybutton.contenthorizontalalignment = uicontrolcontenthorizontalalignmentleft;
[1]http://s23.postimg.org/g8hxmihyv/screen_shot_2013_08_07_at_5_45_40_pm.png "snapshot"
if set entire button red, looks this. [1] http://s21.postimg.org/xdwrziphv/screen_shot_2013_08_07_at_5_50_15_pm.png "snapshot2"
that's because you're settings background color red titlelabel. try setting background color of button while using custom button , changing corner radius of button's layer (#import <quartzcore/quartzcore.h>
). ex:
uibutton *button = [uibutton buttonwithtype:uibuttontypecustom]; [button setbackgroundcolor:[uicolor redcolor]]; [button.layer setcornerradius:5.0f];
additionally, may need change color of titlelabel clearcolor.
Comments
Post a Comment