• UIButton UIBarButtonItem用法


     1 #pragma mark 快速创建一个item
     2 - (UIBarButtonItem *)itemWithNormal:(NSString *)normal highlighted:(NSString *)highlighted selector:(SEL)selector {
     3     // 初始化按钮
     4     UIButton *button = [[[UIButton alloc] init] autorelease];
     5      button.title.font = [UIFont systemFontOfSize:10];
    6 // 设置按钮背景图片 7 UIImage *normalImg = [UIImage imageNamed:normal]; 8 UIImage *highlightedImg = [UIImage imageNamed:highlighted]; 9 button.bounds = CGRectMake(0, 0, normalImg.size.width, normalImg.size.height); 10 [button setBackgroundImage:normalImg forState:UIControlStateNormal]; 11 [button setBackgroundImage:highlightedImg forState:UIControlStateHighlighted]; 12 // 监听按钮点击 13 [button addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside]; 14 // 初始化item 15 return [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease]; 16 }
    1 // 设置左边
    2 self.navigationItem.leftBarButtonItem = [self itemWithNormal:@"left.png" 
    highlighted:@"leftHigh.png" selector:@selector(send)]; 3 4 // 设置右边 5 self.navigationItem.rightBarButtonItem = [self itemWithNormal:@"right.png"
    highlighted:@"rightHigh.png" selector:@selector(refresh)];
    1 // 设置cell的背景色
    2  UIView *bg = [[[UIView alloc] init] autorelease];
    3  bg.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
    4   cell.backgroundView = bg;
    1 // 设置cell选中的背景
    2 UIView *selectdBg = [[[UIView alloc] init] autorelease];
    3 selectdBg.backgroundColor = [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1];
    4 cell.selectedBackgroundView = selectdBg;
    1 //设置按钮的标题和颜色
    2 [btn setNormalBg:@"normal.png" andHightlighted:@"highlight.png"];
    3 [btn setTitle@"title" forState:UIControlStateNormal];
    4 [btn setTitleColor:[UIColor balckColor] forState:UIControlStateNormal];
    UIButton *button = [[[UIButton alloc] init] autorelease];
    //
    字体大小 button.title.font = [UIFont systemFontOfSize:10]; //自动对齐 button.title.textAlignment = NSTextAlignmentCenter; //设置背景图片 [button setBackgroundImage:[UIImage resizeImage:@"image.png"] forState:UIControlStateNormal];
    1 UIButton *btn = [[UIButton alloc] init];
    2 UIImage *imageNormal = [UIImage imageNamed:"@image.png"];
    3 [btn setBackgroundImage:imageNormal forState:UIControlStateNormal];
    4 UIImage *highLight = [UIImage imageNamed:"@high.png"];
    5 [btn setBackgroundImage:imageNormal forState:UIControlStateHighlighted];
    6 UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithCustomView:btn] autorelease];
    7 viewController.navigationItem.rightBarButtonItem = item;
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    runtest.sh
    写代码:简单的三元运算
    写代码:用户交互显示类似省市县三级联动的选择
    写代码:列举布尔值是False的所有值
    写代码:求集合
    写代码:利用For循环和while输出1-100
    写代码:利用for循环和range输出9*9乘法表
    写代码:查找列表中元素,移除每个元素的空格,并查找以a或A开头并且以c结尾的元素。
    写代码:利用下划线将列表的每个元素拼接成字符串,li=["alex","eric","rain"]
    写代码:购物车程序
  • 原文地址:https://www.cnblogs.com/wangshengl9263/p/3232200.html
Copyright © 2020-2023  润新知