Code creation button UIButton:
(i) Basic settings
Create an Intermediate "+" button
UIButton *addbtn = [[UIButton alloc] init];
Set the default background picture
[Addbtn setbackgroundimage:[uiimage imagenamed:@ "Addbuttonicon"] forstate:uicontrolstatenormal];
Set the background picture when pressed
[Addbtn setbackgroundimage:[uiimage imagenamed:@ "addbuttonicon-active"] forstate:uicontrolstatehighlighted];
Add Response Events
[Addbtn addtarget:self Action: @selector (Addbtndidclick) forcontrolevents:uicontroleventtouchupinside];
Add a button to the Tabbar
[Self addsubview:addbtn];
(b) Setting the size and position
Set the position of the "+" button
Self.addButton.centerX = Self.centerx;
Self.addButton.centerY = self.height * 0.5-1.5 * addbuttonmargin;
Set the size of the "+" button to the size of the picture
Self.addButton.size = Cgsizemake (Self.addButton.currentBackgroundImage.size.width, Self.addButton.currentBackgroundImage.size.height);
(iii) Implementation of the Click event Processing method Addbtndidclick
Code creation Uilabel:
Create and set the text below the "+" button to "add"
UILabel *ADDLBL = [[UILabel alloc] init];
Addlbl.text = @ "Add";
Addlbl.font = [Uifont systemfontofsize:10];
Addlbl.textcolor = [Uicolor Graycolor];
[Addlbl SizeToFit];
Set the location of the "Add" label
Addlbl.centerx = Self.addButton.centerX;
Addlbl.centery = Cgrectgetmaxy (self.addButton.frame) + 0.5 * addbuttonmargin + 0.5;
[Self ADDSUBVIEW:ADDLBL];
Other control code creation ideas : Set the size, position, set the basic state (such as background picture, title, text size, color), add the view to the parent view, and finally implement the corresponding interactive event processing method (if necessary)
The idea of creating code for common Controls (UIButton, UILabel) for iOS development