zoukankan      html  css  js  c++  java
  • 循环按钮,并且选中 (附效果图)

    效果图

    以下代码均可全部复制,直接到上图的效果图

    #import "ViewController.h"

    @interface ViewController ()

    //设置属性

    @property (nonatomic,strong)NSMutableDictionary *aihao;

    @property (nonatomic,strong)UILabel *carheard;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        [self creatUI];

    }

    #define Screen  [UIScreen mainScreen]

    -(void)creatUI

    {

        NSArray* citys = @[@"旅游",@"汽车",@"房产",@"美食",@"上网",@"投资",@"体育运动",@"影视",@"电影",@"户外",@"阅读"];

        self.aihao = [NSMutableDictionary dictionary];

        for (int i = 0; i<citys.count; i++) {

            UILabel* carheard;

            carheard = [[UILabel alloc]initWithFrame:CGRectMake((i%4)*Screen.bounds.size.width/4+30, (i/4)*Screen.bounds.size.height/15+50 , Screen.bounds.size.width/4, 30)];

            

            UIButton* select = [[UIButton alloc]initWithFrame:CGRectMake(carheard.frame.origin.x-20,carheard.frame.origin.y+8,15,15)];

            [select setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

            [select addTarget:self action:@selector(selectedion:) forControlEvents:UIControlEventTouchUpInside];

            [select setBackgroundImage:[UIImage imageNamed:@"xuanze_default_03"] forState:UIControlStateNormal];

            [carheard setText:citys[i]];

            [carheard setBackgroundColor:[UIColor whiteColor]];

            [carheard setFont:[UIFont systemFontOfSize:14]];

            [self.view addSubview:carheard];

            [self.view addSubview:select];

        }

    }

    -(void)selectedion:(UIButton*)sender{

        if(sender.selected)

        {

            [sender setSelected:NO];

            [sender setBackgroundImage:[UIImage imageNamed:@"xuanze_default_03"] forState:UIControlStateNormal];

            [self.aihao removeObjectForKey:sender.titleLabel.text];

            

        }else{

            [sender setSelected:YES];

            [sender setBackgroundImage:[UIImage imageNamed:@"xuanze_hover_69"] forState:UIControlStateNormal];

        }

        NSLog(@"%@",self.aihao);

    }

  • 相关阅读:
    610K图纸打印新版增值税发票不完整的调整方法 黑盘红盘都兼容
    Teleport Ultra 下载网页修复
    IIS7配置Gzip压缩 JS压强失败的原因
    Destoon B2B 调优SQL后 生成首页仍然慢或不成功的原因
    奈学教育《大数据架构师》课程大纲
    奈学教育《P7架构师》课程大纲
    奈学教育《Java资深研发工程师》课程大纲
    奈学教育《百万架构师》课程大纲
    奈学教育《大数据开发工程师》课程大纲
    奈学教育<P7架构师>课程大纲(第一阶段)
  • 原文地址:https://www.cnblogs.com/liaolijun/p/4565233.html
Copyright © 2011-2022 走看看