UISegmentedControl的所有操作總結_UISegmentedControl

來源:互聯網
上載者:User

UISegmentedControl的所有操作總結:

#import "SegmentedControlTestViewController.h"      @implementation SegmentedControlTestViewController      @synthesize segmentedControl;            /****************************************      Tasks     Initializing a Segmented Control      – initWithItems:       Managing Segment Content      – setImage:forSegmentAtIndex:        – imageForSegmentAtIndex:        – setTitle:forSegmentAtIndex:        – titleForSegmentAtIndex:       Managing Segments      – insertSegmentWithImage:atIndex:animated:        – insertSegmentWithTitle:atIndex:animated:        numberOfSegments  property        – removeAllSegments        – removeSegmentAtIndex:animated:        selectedSegmentIndex  property       Managing Segment Behavior and Appearance      momentary  property        segmentedControlStyle  property        tintColor  property        – setEnabled:forSegmentAtIndex:        – isEnabledForSegmentAtIndex:        – setContentOffset:forSegmentAtIndex:        – contentOffsetForSegmentAtIndex:        – setWidth:forSegmentAtIndex:        – widthForSegmentAtIndex:       *********************************************/      // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.      - (void)viewDidLoad {          NSArray *segmentedArray = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",nil];          //初始化UISegmentedControl          UISegmentedControl *segmentedTemp = [[UISegmentedControl alloc]initWithItems:segmentedArray];          segmentedControl = segmentedTemp;          segmentedControl.frame = CGRectMake(60.0, 10.0, 200.0, 50.0);                    [segmentedControl setTitle:@"two" forSegmentAtIndex:1];//設定指定索引的題目          [segmentedControl setImage:[UIImage imageNamed:@"lan.png"] forSegmentAtIndex:3];//設定指定索引的圖片          [segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"mei.png"] atIndex:2 animated:NO];//在指定索引插入一個選項並設定圖片          [segmentedControl insertSegmentWithTitle:@"insert" atIndex:3 animated:NO];//在指定索引插入一個選項並設定題目          [segmentedControl removeSegmentAtIndex:0 animated:NO];//移除指定索引的選項          [segmentedControl setWidth:70.0 forSegmentAtIndex:2];//設定指定索引選項的寬度          [segmentedControl setContentOffset:CGSizeMake(10.0,10.0) forSegmentAtIndex:1];//設定選項中圖片等的左上方的位置                    //擷取指定索引選項的圖片imageForSegmentAtIndex:          UIImageView *imageForSegmentAtIndex = [[UIImageView alloc]initWithImage:[segmentedControl imageForSegmentAtIndex:1]];          imageForSegmentAtIndex.frame = CGRectMake(60.0, 100.0, 30.0, 30.0);                    //擷取指定索引選項的標題titleForSegmentAtIndex          UILabel *titleForSegmentAtIndex = [[UILabel alloc]initWithFrame:CGRectMake(100.0, 100.0, 30.0, 30.0)];          titleForSegmentAtIndex.text = [segmentedControl titleForSegmentAtIndex:0];                    //擷取總選項數segmentedControl.numberOfSegments          UILabel *numberOfSegments = [[UILabel alloc]initWithFrame:CGRectMake(140.0, 100.0, 30.0, 30.0)];          numberOfSegments.text = [NSString stringWithFormat:@"%d",segmentedControl.numberOfSegments];                    //擷取指定索引選項的寬度widthForSegmentAtIndex:          UILabel *widthForSegmentAtIndex = [[UILabel alloc]initWithFrame:CGRectMake(180.0, 100.0, 70.0, 30.0)];          widthForSegmentAtIndex.text = [NSString stringWithFormat:@"%f",[segmentedControl widthForSegmentAtIndex:2]];                    segmentedControl.selectedSegmentIndex = 2;//設定預設選擇項索引          segmentedControl.tintColor = [UIColor redColor];          segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;//設定樣式          segmentedControl.momentary = YES;//設定在點擊後是否恢複原樣                    [segmentedControl setEnabled:NO forSegmentAtIndex:4];//設定指定索引選項不可選          BOOL enableFlag = [segmentedControl isEnabledForSegmentAtIndex:4];//判斷指定索引選項是否可選          NSLog(@"%d",enableFlag);                    [self.view addSubview:widthForSegmentAtIndex];          [self.view addSubview:numberOfSegments];          [self.view addSubview:titleForSegmentAtIndex];          [self.view addSubview:imageForSegmentAtIndex];          [self.view addSubview:segmentedControl];                    [widthForSegmentAtIndex release];          [numberOfSegments release];          [titleForSegmentAtIndex release];          [segmentedTemp release];          [imageForSegmentAtIndex release];                    //移除所有選項          //[segmentedControl removeAllSegments];          [super viewDidLoad];      }            /*     // Override to allow orientations other than the default portrait orientation.     - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {         // Return YES for supported orientations         return (interfaceOrientation == UIInterfaceOrientationPortrait);     }     */      - (void)didReceiveMemoryWarning {          // Releases the view if it doesn't have a superview.          [super didReceiveMemoryWarning];                    // Release any cached data, images, etc that aren't in use.      }      - (void)viewDidUnload {          // Release any retained subviews of the main view.          // e.g. self.myOutlet = nil;      }            - (void)dealloc {          [segmentedControl release];          [super dealloc];      }      @end


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.