进击的UI------------------UISegmentedControlUISlide
生活随笔
收集整理的這篇文章主要介紹了
进击的UI------------------UISegmentedControlUISlide
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.UISegmentedControl ①:初始 self.segment = [[UISegmentedControl alloc]initWithItems: [NSArray arrayWithObjects:@"一卡通",@"信用卡",@"一網通", nil]]; self.segment.frame = CGRectMake(0, 20, self.frame.size.width, 50); [self addSubview:_segment]; ②:設置標題 [self.rv.segment setTitle:@"第二項" forSegmentAtIndex:0]; ③:默認被選中的選項 self.rv.segment.selectedSegmentIndex? = 1; ④:邊框和字體的顏色 self.rv.segment.tintColor = [UIColor orangeColor]; ⑤:設置圖片 self.rv.segment setImage:(UIImage *) forSegmentAtIndex:<#(NSUInteger)#> ⑥:獲取圖片 self.rv.segment imageForSegmentAtIndex: ⑦:獲取title self.rv.segment titleForSegmentAtIndex:<#(NSUInteger)#> ⑧:插入一個 [self.rv.segment insertSegmentWithTitle:@"3" atIndex:3 animated:YES]; ⑨:刪除一個 [self.rv.segment removeSegmentAtIndex:3 animated:YES]; ⑩:事件 [self.rv.segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; - (void)segmentAction:(UISegmentedControl *)sender{ if (sender.selectedSegmentIndex == 0) { UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 70, self.rv.frame.size.width, self.rv.frame.size.height - 70)]; view1.backgroundColor = [UIColor colorWithRed:arc4random()%2/1.0 green:arc4random()%2/1.0 blue:arc4random()%2/1.0 alpha:1]; [self.rv addSubview:view1]; }else if (sender.selectedSegmentIndex == 1){ UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 70, 375, 600)]; view2.backgroundColor = [UIColor colorWithRed:arc4random()%2/1.0 green:arc4random()%2/1.0 blue:arc4random()%2/1.0 alpha:1]; [self.rv addSubview:view2]; }else if (sender.selectedSegmentIndex == 2){ UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 70, 375, 600)]; view3.backgroundColor = [UIColor colorWithRed:arc4random()%2/1.0 green:arc4random()%2/1.0 blue:arc4random()%2/1.0 alpha:1]; [self.rv addSubview:view3];}} 2.UISlider ①:初始 self.slider = [[UISlider alloc]initWithFrame:CGRectMake(50, 100, 280, 50)]; ②:設置最大值 self.slider.minimumValue = 0; ③:設置最小值 self.slider.maximumValue = 1; ④:設置最大值的滑條顏色 self.slider.maximumTrackTintColor = [UIColor blackColor]; ⑤:設置最小值的滑條顏色 self.slider.minimumTrackTintColor = [UIColor greenColor]; ⑥:右邊加圖片 self.slider.maximumValueImage = [UIImage imageNamed:@"1.png"]; ⑦:左邊加圖片 self.slider.minimumValueImage = [UIImage imageNamed:@"2.png"]; ⑧:圓點顏色 self.slider.thumbTintColor = [UIColor redColor]; ⑨:設置圓點圖片 self.slider setThumbImage:<#(UIImage *)#> forState:<#(UIControlState)#> ⑩:事件 [self.rv.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged]; // 注意:UIControlEventValueChanged的方法 - (void)sliderAction:(UISlider *)sender{ NSLog(@"%f",sender.value);// 獲取當前滑條所在的值 self.rv.alpha = sender.value;// 透明度控制} 3.UIImageView 動畫: - (void)viewDidLoad { // 父類視圖加載完成 [super viewDidLoad]; // 做動態圖的方法 [self MoveImageArr];} - (void)MoveImageArr{ NSMutableArray *imageArr = [NSMutableArray array]; for (int i = 0; i < 7; i++) {?????? NSString *nameStr = [NSString stringWithFormat:@"%d.tiff",i]; [imageArr addObject:[UIImage imageNamed:nameStr]];} self.rv.mv.animationImages = imageArr; // 時間間隔 self.rv.mv.animationDuration = 0.1; // 重復次數 //??? self.rv.mv.animationRepeatCount = 3; // 開始動畫 [self.rv.mv.mvstartAnimating]; // 結束動畫 //??? [self.rv.mv. stopAnimating];} 4.UIControl UIControl 所有控制類的控件直接繼承于UIControl // 核心方法 add target action // 為控制控件通過 addTarget: action: forControlEvents: 方法來添加事件。 // 通過 removeTarget: action: forControlEvents: 來移除事件。 5.已學類的繼承
轉載于:https://www.cnblogs.com/sharkHZ/p/4984128.html
總結
以上是生活随笔為你收集整理的进击的UI------------------UISegmentedControlUISlide的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自定义ViewGroup(1)
- 下一篇: 当装了两个tomcat后,如何修改tom