UIButton *button = [[UIButton Alloc]initWithFrame:CGRectMake (0,100,200,100)]; Add a Click event[ButtonAddTarget:SelfAction@selector (Pushtosecond)forControlEvents:UIControlEventTouchUpInside]; The background color of the entire button (effect when no background picture is available)Button.backgroundcolor = [Uicolor Greencolor]; Add a background picture[Buttonsetbackgroundimage:[UIImageimagenamed:@"01.png"]Forstate:UIControlStateNormal]; Button title[Buttonsettitle:@"Hello world!"Forstate:UIControlStateNormal]; Horizontal alignment of child controls on a buttonButton.contenthorizontalalignment =Uicontrolcontenthorizontalalignmentleft; Vertical alignment of child controls on a buttonButton.contentverticalalignment =Uicontrolcontentverticalalignmenttop; Offset of the content container to offset the text to the right20 megapixelsButton.contentedgeinsets =Uiedgeinsetsmake (0,20, 0, 0); //set the background color of the title Button.titleLabel.backgroundColor = [ span class= "constant" >uicolor purplecolor]; //title color [button settitlecolor:[uicolor yellowcolor]forstate: uicontrolstatenormal]; Button.imageView.contentMode = Uiviewcontentmodescaleaspectfit; [self.view addsubview: Button]; [button release];
Change the title position, text color, background color, etc. on UIButton