We often need to use buttons that require text and images to be displayed simultaneously, for example:
We need to define a UIButton subclass.
Implementation file
-(ID) initWithFrame: (cgrect) frame
{
self = [super initwithframe: frame];
if (self) {
//Can be adjusted according to your own needs
self. Titlelabel. TextAlignment=nstextalignmentright;
Self. Titlelabel. font=[uifontsystemfontofsize:14.0];
self. ImageView . Contentmode = Uiviewcontentmodeleft;
}
return self;
}
Methods for overriding parent class UIButton
Rect with a more button set and returns the text label of the RECT
-(cgrect) Titlerectforcontentrect: (cgrect) contentrect
{
cgfloat Titlew = contentrect. size. width-+;
cgfloat Titleh = contentrect. size. height;
cgfloat Titlex = 0;
cgfloat Titley = 0;
Contentrect = (cgrect) {{Titlex,titley},{titlew,titleh}};
return Contentrect;
}
Rect with a more button set and returns a Uiimageview rect
-(cgrect) Imagerectforcontentrect: (cgrect) contentrect
{
cgfloat Imagew = ;
cgfloat Imageh = ;
cgfloat ImageX = contentrect. size. width-up;
cgfloat imagey = 2.5;
Contentrect = (cgrect) {{Imagex,imagey},{imagew,imageh}};
return Contentrect;
}
Using subclasses of UIButton
Yxpbutton *selectareabutton=[[yxpbuttonalloc] initwithframe:cgrectmake (5, +) ];
[Selectareabutton settitle:@ "graphic mixed"forstate: UIControlStateNormal];
[Selectareabutton setimage: [UIImageimagenamed:@ "Location" ]forstate:uicontrolstatenormal];
[Selectareabutton settitlecolor: [uicolorwhitecolor] Forstate:uicontrolstatenormal];
[NavigationbgviewAddsubview: Selectareabutton];
So that you can implement a button of the graphic mixed