In iOS development, use UIButton to set the title and image, to achieve the Tabbaritem effect, that is, the title in the next, image on:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2F/49/wKioL1OexrfCP8zzAAAI-UZ7fbY747.jpg "title=" screen shot 2014-06-16 pm 6.23.22.png "alt=" Wkiol1oexrfcp8zzaaai-uz7fby747.jpg "/>
At the moment, I find that there are two better ways to do this:
Method one, using uiedgeinsets
uibutton *button = [ uibutton buttonwithtype: Uibuttontypesystem
[button setframe : cgrectmake (100 , 100 , 60 , 60 )];
[Button setbackgroundcolor: [uicolor greencolor];
UIImage *image = [UIImage imagenamed:@ "index"];
[Button settitle:@ "Home" forstate:uicontrolstatenormal];
[Button setimage: Image forstate:uicontrolstatenormal];
//If not set, the default image is left, title is right, center is displayed
The title and image overlap are centered if the following settings are set
button. titleedgeinsets = uiedgeinsetsmake(0.0,-image. Size. width, 0.0, 0.0);
= uiedgeinsetsmake ( 0.0
button. Titlelabel. Bounds. Size. width);
//If set below, the title moves down 40 units, under, image moves up 20 units, on, center display
button. titleedgeinsets = uiedgeinsetsmake (40.0 ,-image.size . width , , 0.0 );
= uiedgeinsetsmake (- 20.0
button. Titlelabel Bounds Size Width
[self. View addsubview: button];
Method Two, overriding UIButton's Layoutsubviews
-(void) layoutsubviews
{
[super layoutsubviews];
Center = . Imageview Center
Center. x = . frame . size . width / 2 ;
= Self Imageview Frame Size Height/ 2
Self. ImageView. Center = Center;
CGRect frame = [ self titlelabel]. frame;
Frame. origin . x = ;
Y = Self Imageview Frame Size Height + 2
frame. Size. Width = self. Frame. Size. width;
Self. Titlelabel. frame = frame;
self Titlelabel Textalignment = Nstextalignmentcenter
[self. Titlelabel setFont: [uifont systemfontofsize:10.0f]];
}