《IOS编程》控制逻辑课后练习 学习手记
来源:互联网 发布:什么是协同过滤算法? 编辑:程序博客网 时间:2024/04/30 08:50
题目:
将UISegmentedControl 对象(分段控件)加入BNRHypnosisViewController 对象的视图……书页码(139)
开始编码:
1.修改
BNRHypnosisterView.m 将之前定义的局部属性 改为全局属性
@property ( strong , nonatomic)UIColor *circleColor; //圆圈颜色定义到.h 文件中即可。
2.BNRHypnosisViewController.m 中增加局部属性
@property (nonatomic,strong) BNRHypnosisterView *backgroundView;
修改
viewDidLoad :
- (void)viewDidLoad { [super viewDidLoad]; //CGRect frame = [UIScreen mainScreen].bounds; CGRect frame = CGRectMake(0.0, 35, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-150); NSLog(@"===>1"); // Do any additional setup after loading the view. self.backgroundView = [[BNRHypnosisterView alloc]initWithFrame:frame]; NSArray *segmentedArray = [[NSArray alloc]initWithObjects:@"随机颜色",@"红色",@"蓝色",@"黄色",nil]; UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray]; segmentedControl.selectedSegmentIndex = 0;//设置默认选择项索引 segmentedControl.frame = CGRectMake(1.0, [UIScreen mainScreen].bounds.size.height-50-60, 318.0, 50.0); segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;//设置样式 [segmentedControl addTarget:self action:@selector(segmentAction:)forControlEvents:UIControlEventValueChanged]; //添加委托方法 [self.view addSubview:self.backgroundView]; [self.view addSubview:segmentedControl]; //self.view = backgroundView;}
新增委托方法segmentAction:
//作业中级练习- (void)segmentAction:(UISegmentedControl *)Seg{ NSInteger Index = Seg.selectedSegmentIndex; //NSLog(@"Index %ld", Index); switch (Index) { case 0:{ float red = (arc4random()%100)/100.0; float blue = (arc4random()%100)/100.0; float green = (arc4random()%100)/100.0; UIColor *randomColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; self.backgroundView.circleColor = randomColor; } break; case 1:{ UIColor *randomColor = [UIColor redColor]; self.backgroundView.circleColor = randomColor; } break; case 2:{ UIColor *randomColor = [UIColor blueColor]; self.backgroundView.circleColor = randomColor; } break; default:{ UIColor *randomColor = [UIColor yellowColor]; self.backgroundView.circleColor = randomColor; } break; } }
搞定。。。
新手学习中,仅供参考
0 0
- 《IOS编程》控制逻辑课后练习 学习手记
- IOS学习--课后练习6
- 逻辑判断_课后练习
- 《IOS编程》深入学习:键值编码 学习手记
- C++编程思想第二章课后练习
- Scala编程思想的课后练习答案
- IOS学习---课后习题1
- IOS学习--课后练习题2
- IOS学习--课后练习题3
- IOS学习--课后练习题5
- 学习数组应用的课后练习
- 学习C++Primer第五版,课后练习。
- 课后练习
- 课后练习
- 课后练习
- 课后练习
- IOS本地推送 学习手记
- unity学习手记之控制角色移动
- 0720linux共享库和静态库制作
- html中字符转义
- what is the film faced plywood
- FZU 2020 组合(Lucas定理)
- ZOJ 3631 Watashi's BG(双向枚举)
- 《IOS编程》控制逻辑课后练习 学习手记
- SpringMVC 用注解Annotation驱动的IoC功能@Autowired @Component
- 初识数据库
- Gym 100712G Heavy Coins(DFS)
- “儿童”计算器
- Gym 100712I Bahosain and Digits(枚举)
- Majority Number II
- 原型模式
- POJ 1753 Flip Game(BFS)