iOS UI 开发按钮的使用
生活随笔
收集整理的這篇文章主要介紹了
iOS UI 开发按钮的使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
IOS UI 開發(fā)之按鈕的使用
// // ViewController.m // 02按鈕的使用介紹 // // Created by 魯軍 on 2021/1/26. //#import "ViewController.h"@interface ViewController () - (IBAction)up; - (IBAction)down:(id)sender; - (IBAction)left:(id)sender; - (IBAction)right;- (IBAction)big;- (IBAction)small;@property (weak, nonatomic) IBOutlet UIButton *btnIcon;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view. }- (IBAction)small {CGRect originFrame = self.btnIcon.frame;//originFrame.size.width += 10;//originFrame.size.height += 10;originFrame.size = CGSizeMake(originFrame.size.width - 10, originFrame.size.height - 10);self.btnIcon.frame = originFrame; }- (IBAction)big {NSLog(@"放大");CGRect originFrame = self.btnIcon.frame;//originFrame.size.width += 10;//originFrame.size.height += 10;originFrame.size = CGSizeMake(originFrame.size.width + 10, originFrame.size.height + 10);self.btnIcon.frame = originFrame; }- (IBAction)right {CGRect originFrame = self.btnIcon.frame;originFrame.origin.x += 10;self.btnIcon.frame = originFrame;}- (IBAction)left:(id)sender {CGRect originFrame = self.btnIcon.frame;originFrame.origin.x -= 10;self.btnIcon.frame = originFrame; }- (IBAction)down:(id)sender {CGRect originFrame = self.btnIcon.frame;originFrame.origin.y += 10;self.btnIcon.frame = originFrame;}- (IBAction)up {NSLog(@"123");CGRect originFrame = self.btnIcon.frame;originFrame.origin.y -= 10;self.btnIcon.frame = originFrame;} @endanimat 的使用
// // ViewController.m // 02按鈕的使用介紹 // // Created by 魯軍 on 2021/1/26. //#import "ViewController.h"@interface ViewController () - (IBAction)move:(UIButton *)sender;- (IBAction)scale:(UIButton *)sender;@property (weak, nonatomic) IBOutlet UIButton *btnIcon;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view. }- (IBAction)scale:(UIButton *)sender {CGRect originFrame = self.btnIcon.frame;if(sender.tag == 100){originFrame.size.width+=10;originFrame.size.height+=10;}else{originFrame.size.width-=10;originFrame.size.height-=10;}// self.btnIcon.frame = originFrame;[UIView animateWithDuration:2.0 animations:^{self.btnIcon.frame = originFrame;}];//通過bounds 修改大小//bounds 雖然也是CGRect類型,但是 x y 的值始終是0 // CGRect originBounds = self.btnIcon.bounds; // NSLog(@"%@",NSStringFromCGRect(originBounds)); // // // // if(sender.tag == 100) // { // originBounds.size.width +=10; // originBounds.size.height +=10; // // } // if(sender.tag==200){ // originBounds.size.width -=10; // originBounds.size.height -=10; // }// self.btnIcon.bounds = originBounds; // // self.btnIcon.bounds = originBounds; // [UIView beginAnimations:nil context:nil]; // [UIView setAnimationDuration:2]; // // self.btnIcon.bounds = originBounds; // // [UIView commitAnimations];}- (IBAction)move:(UIButton *)sender {//NSLog(@"111");// CGRect originFrame = self.btnIcon.frame; // // switch (sender.tag) { // case 10: // originFrame.origin.y -= 10; // break; // // case 20: // originFrame.origin.x += 10; // break; // case 30: // originFrame.origin.y += 10; // break; // case 40: // originFrame.origin.x -= 10; // break; // } // self.btnIcon.frame=originFrame; ////通過 center 修改大小CGPoint centerPoint = self.btnIcon.center;switch (sender.tag) {case 10:centerPoint.y-=100;break;case 20:centerPoint.x+=100;break;case 30:centerPoint.y+=100;break;case 40:centerPoint.x-=100;break;}//重新扶植 center//沒有動畫 直接執(zhí)行 // self.btnIcon.center = centerPoint; // [UIView beginAnimations:nil context:nil]; // [UIView setAnimationDuration:2]; // // self.btnIcon.center = centerPoint; // // [UIView commitAnimations]; //[UIView animateWithDuration:2.0 animations:^{self.btnIcon.center = centerPoint;}];} @end純代碼實現(xiàn)按鈕
// // ViewController.m // 04動態(tài)創(chuàng)建按鈕 // // Created by 魯軍 on 2021/1/30. //#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.//UIButton *button = [[UIButton alloc] init];UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[button setTitle:@"點(diǎn)我吧" forState:UIControlStateNormal];[button setTitle:@"摸我干啥" forState:UIControlStateHighlighted];//設(shè)置不同狀態(tài)下的顏色[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];[button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];UIImage *imgNormal = [UIImage imageNamed:@"btn_01"];UIImage *imgHighlighted = [UIImage imageNamed:@"btn_02"];[button setBackgroundImage:imgNormal forState:UIControlStateNormal];[button setBackgroundImage:imgHighlighted forState:UIControlStateHighlighted];button.frame = CGRectMake(50, 100,100, 100);//單擊事件[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];//動態(tài)的創(chuàng)建的按鈕加到控制器的管理的那個view里面[self.view addSubview:button];}-(void)buttonClick{NSLog(@"1234"); }@end總結(jié)
以上是生活随笔為你收集整理的iOS UI 开发按钮的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 哪些人不能要 哪些人不能留
- 下一篇: 软件质量管理之困境与对策思考