記錄下UIButton的圖文妙用和子控制項的優先顯示

来源:http://www.cnblogs.com/tandaxia/archive/2016/10/19/5975729.html
-Advertisement-
Play Games

UIButton的用處特別多,這裡只記錄下把按鈕應用在圖文顯示的場景,和需要把圖片作為按鈕的背景圖片顯示場景; 另外記錄下在父控制項的子控制項優先顯示方法(控制項置於最前面和置於最後面)。 先上效果圖: 1、當在某個地方既需要顯示圖片,還需要顯示文字,另外還要有點擊功能的時候,這時按鈕是個很好的選擇。 按 ...


  UIButton的用處特別多,這裡只記錄下把按鈕應用在圖文顯示的場景,和需要把圖片作為按鈕的背景圖片顯示場景;

另外記錄下在父控制項的子控制項優先顯示方法(控制項置於最前面和置於最後面)。

先上效果圖:

 

1、當在某個地方既需要顯示圖片,還需要顯示文字,另外還要有點擊功能的時候,這時按鈕是個很好的選擇。

  按鈕中的圖片和文字的距離可以自由調整,圖片的也可以上下左右翻轉。日常項目中像這些場景都是很容易碰到的。

  按鈕圖文設置、圖文位置移動、按鈕中圖片翻轉示例代碼:

/** 測試圖文並茂的按鈕,圖文移動 */
- (void)addMoveImgAndTextButton{
    //1、創建一個按鈕:30x50
    UIButton *iconBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 100, 150, 80)];
    [iconBtn setTitle:@"我的好友" forState:UIControlStateNormal];
    [iconBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [iconBtn setImage:[UIImage imageNamed:@"pointer"] forState:UIControlStateNormal];
    iconBtn.layer.borderColor = [UIColor redColor].CGColor;  //邊框顏色
    iconBtn.layer.borderWidth = 1;  //邊框寬度
    iconBtn.titleLabel.backgroundColor = [UIColor greenColor]; //文字顏色
    iconBtn.imageView.backgroundColor = [UIColor blackColor]; //圖片顏色
    [iconBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:iconBtn];
    self.iconBtn = iconBtn;
    
    //2、移動iconBtn按鈕圖片和文字
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(170, 100, 120, 45)];
    [btn setTitle:@"圖右移字左移" forState:UIControlStateNormal];
    btn.titleLabel.numberOfLines = 0;
    [btn setBackgroundColor:[UIColor blackColor]];
    [btn addTarget:self action:@selector(changeBtnFrame:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    //3、移動iconBtn按鈕圖片和文字
    UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(170, 150, 120, 45)];
    [btn2 setTitle:@"字右移圖左移" forState:UIControlStateNormal];
    btn2.titleLabel.numberOfLines = 0;
    [btn2 setBackgroundColor:[UIColor blackColor]];
    [btn2 addTarget:self action:@selector(changeBtnFrame2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    
    //分割線
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 210, 500, 1)];
    lineView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:lineView];
}

/** 點擊按鈕使圖片位置翻轉 */
- (void)clickButton:(UIButton *)sender{
    sender.imageView.transform = CGAffineTransformRotate(sender.imageView.transform, M_PI);
}

/** 移動圖片和文字位置 */
- (void)changeBtnFrame:(UIButton *)sender{
    
    UIEdgeInsets edge = self.iconBtn.imageEdgeInsets;
    CGFloat changeNum = 10;
    self.iconBtn.imageEdgeInsets = UIEdgeInsetsMake(0, edge.left + changeNum, 0, -(edge.left + changeNum));
    self.iconBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(edge.left + changeNum), 0, edge.left + changeNum);
    
    NSLog(@"edge.left: %f, edge.right: %f", edge.left, edge.right);
}

/** 反方向移動圖片和文字位置 */
- (void)changeBtnFrame2:(UIButton *)sender{
    
    UIEdgeInsets edge = self.iconBtn.imageEdgeInsets;
    CGFloat changeNum = 10;
    self.iconBtn.imageEdgeInsets = UIEdgeInsetsMake(0, edge.left - changeNum, 0, -(edge.left - changeNum));
    self.iconBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(edge.left - changeNum), 0, edge.left - changeNum);
    
    NSLog(@"...edge.left: %f, edge.right: %f", edge.left, edge.right);
}
View Code

 

2、有時候需要給按鈕設置背景圖片,一般UI給個圖片,然後我們自己對圖片進行處理,讓背景圖片自適應按鈕展示,矩形圓角。

  但是有時候,產品要求顯示的按鈕左右必須是圓形的,這時候雖然可以讓ui切個適配的圖片做背景,其實針對如果是背景圖片是純色的話,我們可以利用

控制項的layer.masksToBounds, 和layer.cornerRadius屬性來讓按鈕或者其他控制項左右兩邊都是圓形的。

下麵寫了五個橙色背景的按鈕作比較:背景圖片和按鈕尺寸匹配的、背景圖片和按鈕尺寸或偏大或偏小的、處理背景圖片讓背景圖片自適應按鈕的、不用背景圖片使用圖層來設置按鈕左右圓形的:

/** 測試給按鈕設置背景圖片 */
- (void)addBackgroundImgButton{
    //4、96x25 按鈕設置背景圖片,顏色rgb(255,145,0)
    UIImage *img = [UIImage imageNamed:@"btn_bg"];
    UIButton *clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 240, 96, 25)];
    [clickBtn setBackgroundImage:img forState:UIControlStateNormal];
    [clickBtn setTitle:@"click Me" forState:UIControlStateNormal];
    [self.view addSubview:clickBtn];
    
    //4.2 給按鈕設置背景圖片, 按鈕圖片不適配
    UIButton *clickBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(120, 220, 120, 50)];
    [clickBtn2 setBackgroundImage:img forState:UIControlStateNormal];
    [clickBtn2 setTitle:@"click Me" forState:UIControlStateNormal];
    [self.view addSubview:clickBtn2];
    
    //4.3 給按鈕設置背景圖片,按鈕和圖片不適配
    UIButton *clickBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(260, 240, 80, 15)];
    [clickBtn3 setBackgroundImage:img forState:UIControlStateNormal];
    [clickBtn3 setTitle:@"click Me" forState:UIControlStateNormal];
    [self.view addSubview:clickBtn3];
    
    //4.4 處理背景圖片,讓背景圖片自適應按鈕
    NSLog(@"img.size: %@", NSStringFromCGSize(img.size));
    UIImage *newImg = [img stretchableImageWithLeftCapWidth:img.size.width/2 topCapHeight:img.size.height/2];
    NSLog(@"newImg.size: %@", NSStringFromCGSize(newImg.size));
    UIButton *clickBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(10, 300, 150, 60)];
    [clickBtn4 setBackgroundImage:newImg forState:UIControlStateNormal];
    [clickBtn4 setTitle:@"click Me" forState:UIControlStateNormal];
    [self.view addSubview:clickBtn4];
    
    //4.5 按鈕不使用背景圖片,設置背景顏色當做有背景圖片
    UIButton *clickBtn5 = [[UIButton alloc] initWithFrame:CGRectMake(180, 300, 150, 60)];
    [clickBtn5 setTitle:@"click Me" forState:UIControlStateNormal];
    clickBtn5.layer.masksToBounds = YES;
    clickBtn5.layer.cornerRadius = 30;
    clickBtn5.backgroundColor = [UIColor colorWithRed:255/255.f green:145/255.f blue:0 alpha:1];
    [self.view addSubview:clickBtn5];
    
    //分割線
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 380, 500, 1)];
    lineView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:lineView];
}
View Code

 

3、在有些場景下,需要控制控制項的優先顯示或者置後顯示,需要用到方法

- (void)bringSubviewToFront:(UIView *)view;  // 將子控制項view顯示在父控制項的所有子控制項的最前面

- (void)sendSubviewToBack:(UIView *)view;  //將子控制項view顯示在父控制項的所有子控制項的最後面

示例代碼:

/** 測試子控制項的優先顯示(置前和置後) */
- (void)testSubControlShowFront{
    //1、紅色view
    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(10, 420, 200, 200)];
    redView.backgroundColor = [UIColor redColor];
    redView.tag = 11;
    [self.view addSubview:redView];
    
    //2、黑色view
    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(30, 400, 200, 200)];
    blackView.backgroundColor = [UIColor blackColor];
    blackView.tag = 12;
    [self.view addSubview:blackView];
    
    //3、紫色view
    UIView *purpleView = [[UIView alloc] initWithFrame:CGRectMake(50, 440, 200, 200)];
    purpleView.backgroundColor = [UIColor purpleColor];
    purpleView.tag = 13;
    [self.view addSubview:purpleView];
    
    //添加操作按鈕
    UIButton *operatorBtn = [[UIButton alloc] initWithFrame:CGRectMake(280, 400, 100, 30)];
    [operatorBtn setTitle:@"紅色置前" forState:UIControlStateNormal];
    operatorBtn.tag = 1;
    operatorBtn.backgroundColor = [UIColor blackColor];
    [operatorBtn addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:operatorBtn];
    
    UIButton *operatorBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(280, 450, 100, 30)];
    [operatorBtn2 setTitle:@"黑色置前" forState:UIControlStateNormal];
    operatorBtn2.tag = 2;
    operatorBtn2.backgroundColor = [UIColor blackColor];
    [operatorBtn2 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:operatorBtn2];
    
    UIButton *operatorBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(280, 500, 100, 30)];
    [operatorBtn3 setTitle:@"紫色置前" forState:UIControlStateNormal];
    operatorBtn3.tag = 3;
    operatorBtn3.backgroundColor = [UIColor blackColor];
    [operatorBtn3 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:operatorBtn3];
    
    UIButton *operatorBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(280, 550, 100, 30)];
    [operatorBtn4 setTitle:@"紫色置後" forState:UIControlStateNormal];
    operatorBtn4.tag = 4;
    operatorBtn4.backgroundColor = [UIColor redColor];
    [operatorBtn4 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:operatorBtn4];
}
/** 操作按鈕,切換view置前顯示 */
- (void)changeViewToFrontShow:(UIButton *)sender{
    
    if (sender.tag == 1){
        //紅色置前
        UIView *redView = [self.view viewWithTag:11];
        
        //將子控制項redView在父控制項view的所有子控制項的最前面顯示
        [self.view bringSubviewToFront:redView];
    }
    else if (sender.tag == 2){
        //黑色置前
        UIView *blackView = [self.view viewWithTag:12]; //獲取黑色子控制項
        
        //將子控制項blackView在父控制項view的所有子控制項的最前面顯示
        [self.view bringSubviewToFront:blackView];
        
    }
    else if (sender.tag == 3){
        //紫色置前
        UIView *purpleView = [self.view viewWithTag:13]; //獲取紫色子控制項
        
        //將子控制項purpleView在父控制項view的所有子控制項的最前面顯示
        [self.view bringSubviewToFront:purpleView];
    }
    else if (sender.tag == 4){
        //紫色置後
        UIView *purpleView = [self.view viewWithTag:13]; //獲取紫色子控制項
        
        //將子控制項purpleView在父控制項view的所有子控制項的最後面顯示
        [self.view sendSubviewToBack:purpleView];
    }
}
View Code

 

------------------------------------------------------------------------------

-----  完整代碼  ------

//
//  TestButtonVC.m
//  tan_iosTwo
//
//  Created by PX_Mac on 16/10/16.
//
//

#import "TestButtonVC.h"

@interface TestButtonVC ()

@property (nonatomic, weak) UIButton *iconBtn; //帶文字和圖片的按鈕

@end

@implementation TestButtonVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addMoveImgAndTextButton]; //添加圖文並茂的按鈕,測試按鈕上的圖文移動
    
    [self addBackgroundImgButton]; //添加設置背景圖片的按鈕
    
    [self testSubControlShowFront]; //測試子控制項的優先或置後顯示
}

/** 測試圖文並茂的按鈕,圖文移動 */
- (void)addMoveImgAndTextButton{
    //1、創建一個按鈕:30x50
    UIButton *iconBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 100, 150, 80)];
    [iconBtn setTitle:@"我的好友" forState:UIControlStateNormal];
    [iconBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [iconBtn setImage:[UIImage imageNamed:@"pointer"] forState:UIControlStateNormal];
    iconBtn.layer.borderColor = [UIColor redColor].CGColor;  //邊框顏色
    iconBtn.layer.borderWidth = 1;  //邊框寬度
    iconBtn.titleLabel.backgroundColor = [UIColor greenColor]; //文字顏色
    iconBtn.imageView.backgroundColor = [UIColor blackColor]; //圖片顏色
    [iconBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:iconBtn];
    self.iconBtn = iconBtn;
    
    //2、移動iconBtn按鈕圖片和文字
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(170, 100, 120, 45)];
    [btn setTitle:@"圖右移字左移" forState:UIControlStateNormal];
    btn.titleLabel.numberOfLines = 0;
    [btn setBackgroundColor:[UIColor blackColor]];
    [btn addTarget:self action:@selector(changeBtnFrame:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    //3、移動iconBtn按鈕圖片和文字
    UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(170, 150, 120, 45)];
    [btn2 setTitle:@"字右移圖左移" forState:UIControlStateNormal];
    btn2.titleLabel.numberOfLines = 0;
    [btn2 setBackgroundColor:[UIColor blackColor]];
    [btn2 addTarget:self action:@selector(changeBtnFrame2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    
    //分割線
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 210, 500, 1)];
    lineView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:lineView];
}

/** 點擊按鈕使圖片位置翻轉 */
- (void)clickButton:(UIButton *)sender{
    sender.imageView.transform = CGAffineTransformRotate(sender.imageView.transform, M_PI);
}

/** 移動圖片和文字位置 */
- (void)changeBtnFrame:(UIButton *)sender{
    
    UIEdgeInsets edge = self.iconBtn.imageEdgeInsets;
    CGFloat changeNum = 10;
    self.iconBtn.imageEdgeInsets = UIEdgeInsetsMake(0, edge.left + changeNum, 0, -(edge.left + changeNum));
    self.iconBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(edge.left + changeNum), 0, edge.left + changeNum);
    
    NSLog(@"edge.left: %f, edge.right: %f", edge.left, edge.right);
}

/** 反方向移動圖片和文字位置 */
- (void)changeBtnFrame2:(UIButton *)sender{
    
    UIEdgeInsets edge = self.iconBtn.imageEdgeInsets;
    CGFloat changeNum = 10;
    self.iconBtn.imageEdgeInsets = UIEdgeInsetsMake(0, edge.left - changeNum, 0, -(edge.left - changeNum));
    self.iconBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(edge.left - changeNum), 0, edge.left - changeNum);
    
    NSLog(@"...edge.left: %f, edge.right: %f", edge.left, edge.right);
}

/** 測試給按鈕設置背景圖片 */
- (void)addBackgroundImgButton{
    //4、96x25 按鈕設置背景圖片,顏色rgb(255,145,0)
    UIImage *img = [UIImage imageNamed:@"btn_bg"];
    UIButton *clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 240, 96, 25)];
    [clickBtn setBackgroundImage:img forState:UIControlStateNormal];
    [clickBtn setTitle:@"click Me" forState:UIControlStateNormal];
    [self.view addSubview:clickBtn];
    
    //4.2 給按鈕設置背景圖片, 按鈕圖片不適配
    UIButton *clickBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(120, 220, 120, 50)];
    [clickBtn2 setBackgroundImage:img forState:UIControlStateNormal];
    [clickBtn2 setTitle:@"click Me" forState:UIControlStateNormal];
    [self.view addSubview:clickBtn2];
    
    //4.3 給按鈕設置背景圖片,按鈕和圖片不適配
    UIButton *clickBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(260, 240, 80, 15)];
    [clickBtn3 setBackgroundImage:img forState:UIControlStateNormal];
    [clickBtn3 setTitle:@"click Me" forState:UIControlStateNormal];
    [self.view addSubview:clickBtn3];
    
    //4.4 處理背景圖片,讓背景圖片自適應按鈕
    NSLog(@"img.size: %@", NSStringFromCGSize(img.size));
    UIImage *newImg = [img stretchableImageWithLeftCapWidth:img.size.width/2 topCapHeight:img.size.height/2];
    NSLog(@"newImg.size: %@", NSStringFromCGSize(newImg.size));
    UIButton *clickBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(10, 300, 150, 60)];
    [clickBtn4 setBackgroundImage:newImg forState:UIControlStateNormal];
    [clickBtn4 setTitle:@"click Me" forState:UIControlStateNormal];
    [self.view addSubview:clickBtn4];
    
    //4.5 按鈕不使用背景圖片,設置背景顏色當做有背景圖片
    UIButton *clickBtn5 = [[UIButton alloc] initWithFrame:CGRectMake(180, 300, 150, 60)];
    [clickBtn5 setTitle:@"click Me" forState:UIControlStateNormal];
    clickBtn5.layer.masksToBounds = YES;
    clickBtn5.layer.cornerRadius = 30;
    clickBtn5.backgroundColor = [UIColor colorWithRed:255/255.f green:145/255.f blue:0 alpha:1];
    [self.view addSubview:clickBtn5];
    
    //分割線
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 380, 500, 1)];
    lineView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:lineView];
}

/** 測試子控制項的優先顯示(置前和置後) */
- (void)testSubControlShowFront{
    //1、紅色view
    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(10, 420, 200, 200)];
    redView.backgroundColor = [UIColor redColor];
    redView.tag = 11;
    [self.view addSubview:redView];
    
    //2、黑色view
    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(30, 400, 200, 200)];
    blackView.backgroundColor = [UIColor blackColor];
    blackView.tag = 12;
    [self.view addSubview:blackView];
    
    //3、紫色view
    UIView *purpleView = [[UIView alloc] initWithFrame:CGRectMake(50, 440, 200, 200)];
    purpleView.backgroundColor = [UIColor purpleColor];
    purpleView.tag = 13;
    [self.view addSubview:purpleView];
    
    //添加操作按鈕
    UIButton *operatorBtn = [[UIButton alloc] initWithFrame:CGRectMake(280, 400, 100, 30)];
    [operatorBtn setTitle:@"紅色置前" forState:UIControlStateNormal];
    operatorBtn.tag = 1;
    operatorBtn.backgroundColor = [UIColor blackColor];
    [operatorBtn addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:operatorBtn];
    
    UIButton *operatorBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(280, 450, 100, 30)];
    [operatorBtn2 setTitle:@"黑色置前" forState:UIControlStateNormal];
    operatorBtn2.tag = 2;
    operatorBtn2.backgroundColor = [UIColor blackColor];
    [operatorBtn2 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:operatorBtn2];
    
    UIButton *operatorBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(280, 500, 100, 30)];
    [operatorBtn3 setTitle:@"紫色置前" forState:UIControlStateNormal];
    operatorBtn3.tag = 3;
    operatorBtn3.backgroundColor = [UIColor blackColor];
    [operatorBtn3 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:operatorBtn3];
    
    UIButton *operatorBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(280, 550, 100, 30)];
    [operatorBtn4 setTitle:@"紫色置後" forState:UIControlStateNormal];
    operatorBtn4.tag = 4;
    operatorBtn4.backgroundColor = [UIColor redColor];
    [operatorBtn4 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:operatorBtn4];
}
/** 操作按鈕,切換view置前顯示 */
- (void)changeViewToFrontShow:(UIButton *)sender{
    
    if (sender.tag == 1){
        //紅色置前
        UIView *redView = [self.view viewWithTag:11];
        
        //將子控制項redView在父控制項view的所有子控制項的最前面顯示
        [self.view bringSubviewToFront:redView];
    }
    else if (sender.tag == 2){
        //黑色置前
        UIView *blackView = [self.view viewWithTag:12]; //獲取黑色子控制項
        
        //將子控制項blackView在父控制項view的所有子控制項的最前面顯示
        [self.view bringSubviewToFront:blackView];
        
    }
    else if (sender.tag == 3){
        //紫色置前
        UIView *purpleView = [self.view viewWithTag:13]; //獲取紫色子控制項
        
        //將子控制項purpleView在父控制項view的所有子控制項的最前面顯示
        [self.view bringSubviewToFront:purpleView];
    }
    else if (sender.tag == 4){
        //紫色置後
        UIView *purpleView = [self.view viewWithTag:13]; //獲取紫色子控制項
        
        //將子控制項purpleView在父控制項view的所有子控制項的最後面顯示
        [self.view sendSubviewToBack:purpleView];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
View Code

 

原文鏈接:http://www.cnblogs.com/tandaxia/p/5975729.html


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 一、字元串轉JSON 在網路請求時,如果服務端返回的是字元串,那麼就需要我們自己封裝一個類,將請求下來的字元串轉換成json對象,從而存入模型中。 註意: 字元串中如果含有一些特殊轉意符(如\n、\t等),需要先對字元串進行處理。 示例代碼如下: 二、圖片拉伸 三、Label文字自適應frame 方 ...
  • GCD定時器 圖片上繪製文字 查找一個視圖的所有子視圖 計算文件大小 UIView的設置部分圓角 計算字元串字元長度,一個漢字算兩個字元 防止滾動視圖手勢覆蓋側滑手勢 去掉導航欄返回的標題 字元串中是否含有中文 dispatch_group的使用 UITextField每四位加一個空格,實現代理 獲 ...
  • 軟引用 和 弱引用 1. SoftReference<T>:軟引用-->當虛擬機記憶體不足時,將會回收它指向的對象;需要獲取對象時,可以調用get方法。 2. WeakReference<T>:弱引用-->隨時可能會被垃圾回收器回收,不一定要等到虛擬機記憶體不足時才強制回收。要獲取對象時,同樣可以調用g ...
  • 一、介紹 先來介紹一下listview更新數據的幾種方法,目前我知道的方法有如下幾種: 1. 每次更新數據時都調用listview.setadapter(); 2. 每次更新數據時都調用adapter.notifydatasetchanged(); 3. 在自定義的adapter里添加更新函數upd ...
  • 撥打電話小編從網上找到三種,在這裡做一些總結和比較 1、基本使用 這種方法,撥打完電話回不到原來的應用,會停留在通訊錄里,而且是直接撥打,不彈出提示! 在iOS9.0之後,這個方法也是可以回到原來的應用 2、推薦使用 這種方法,打完電話後還會回到原來的程式,也會彈出提示! 3、不建議使用,做瞭解就可 ...
  • 思路: 1.創建一個單例 2.把接收的數據存在本地的 plist,不適用於大量數據,每次讀取第一個數據,讀取完成刪除整個 plist,再把剩下的重新存進 plist 3.根據動畫代理,監聽動畫執行結束,將動畫實例置為 nil 4.判斷動畫實例是否為空,使得切換界面,跑馬燈繼續,而不是重新開始 5.切 ...
  • WebView讓我們方便的使用熟悉的Html/JS/Css來開發APP。但是,當出現問題時,卻沒有PC上那麼方便的排查問題。PC上,前端的問題我們可以使用Chrome的開發者工具方便的調試。Android上怎麼調試呢?今天發現Chrome提供了遠程調試! 如果出現的調試視窗是空白的,可能是如下原因造 ...
  • 突然模擬器報錯:unable to boot the simulator(無法啟動模擬器) 試了好幾種解決辦法,刪除所有的模擬器重啟以後再添加,刪除鑰匙串登陸中的證書,重新安裝Xcode都不行 最後通過這種方式解決了 重新啟動mac 進度條載入的時候一直按command+R進入設置界面,打開界面的左 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...