IOSApplication create Empty project custom UIButton, iosuibutton
I recently started to learn about IOS. I cannot set many attributes of the control in the default Storyboard generated in Xcode5, so I tried to hand-Write the button in an empty project. If there is an error, please correct it, learn together.
1. Create a ViewController class named MCViewController.
2. Create the mccontroller controller and set the Root View of the window to mccontroller.
AppDelegate. m
1-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions 2 {3 self. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; 4 // Override point for customization after application launch. 5 self. window. backgroundColor = [UIColor whiteColor]; 6 [self. window makeKeyAndVisible]; 7 // custom code 8 MCViewController * mccontroller = [[MCViewController alloc] init]; 9 self. window. rootViewController = mccontroller; 10 // code end11 return YES; 12}
3. Create button
MCViewController. m
1-(void) viewDidLoad 2 {3 [super viewDidLoad]; 4 // Do any additional setup after loading the view. 5 6 // btn_enter defines 7 UIButton * btn_enter = [UIButton buttonWithType: Large]; 8 btn_enter.frame = CGRectMake (20,360,280, 40); 9 btn_enter.backgroundColor = [UIColor clearColor]; 10 [btn_enter.layer border: YES]; 11 [btn_enter.layer setCornerRadius: 10.0]; // set the radius of the four rounded corners of the rectangle to 12 [btn_enter.layer setBorderWidth: 1.0]; // Border Width 13 [btn_enter setTitle: @ "click" forState: UIControlStateNormal]; 14 [btn_enter addTarget: self action: @ selector (click_btn_enter :) forControlEvents: UIControlEventTouchUpInside]; 15 [self. view addSubview: btn_enter]; 16 17 // btn_quit defines 18 UIButton * btn_quit = [UIButton buttonWithType: Hangzhou]; 19 btn_quit.frame = CGRectMake (20,420,280, 40 ); 20 bytes = [UIColor clearColor]; 21 [btn_quit.layer setMasksToBounds: YES]; 22 [reset setCornerRadius: 10]; 23 [btn_quit.layer setBorderWidth: 1.0]; 24 [btn_quit setTitle: @ "exit" forState: UIControlStateNormal]; 25 [btn_quit addTarget: self action: @ selector (click_btn_quit :) forControlEvents :( UIControlEventTouchUpInside)]; 26 [self. view addSubview: btn_quit]; 27}
4. Declare button actions
MCViewController. h
1 @interface MCViewController : UIViewController2 -(IBAction)click_btn_enter:(UIButton *)sender;3 -(IBAction)click_btn_quit:(UIButton *)sender;4 @end
5. Implement button actions
MCViewController. m
1 -(IBAction)click_btn_enter:(UIButton *)sender{2 NSLog(@"I am enter!!!");3 }4 5 -(IBAction)click_btn_quit:(UIButton *)sender{6 NSLog(@"I am quit!!!");7 }
In Microsoft Visual C ++, when A project is created, what areas does A simple application and an empty project have?
A simple application has sample code
An empty project only has a blank project. You need to add the source file yourself.
In iOS, how can I use code to set the text attribute of UIButton,
Button. titleLabel. text = "";