日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS UI 开发按钮的使用

發(fā)布時間:2023/12/18 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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;} @end

animat 的使用

// // 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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。