zoukankan      html  css  js  c++  java
  • iPhone控件之UISwitch

     1 //
    2 // UITestViewController.m
    3 // UITest
    4 //
    5
    6 #import "UITestViewController.h"
    7
    8 @implementation UITestViewController
    9
    10 -(void)switchAction:(id)sender
    11 {
    12 NSLog(@"switch changed");
    13 }
    14
    15 - (void)viewDidLoad {
    16
    17 [super viewDidLoad];
    18
    19 CGRect switchRect = CGRectMake(120,50,0,0);
    20 UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:switchRect];
    21 [mySwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    22
    23 //customize the appearance
    24 UIView *mainView = [[[[mySwitch subviews] objectAtIndex:0] subviews] objectAtIndex:2];
    25 UILabel *onLabel = [[mainView subviews] objectAtIndex:0];
    26 UILabel *offLabel = [[mainView subviews] objectAtIndex:1];
    27
    28 //change the text
    29 onLabel.text = @"YES";
    30 offLabel.text = @"NO";
    31
    32 //change the text color
    33 onLabel.textColor = [UIColor yellowColor];
    34 offLabel.textColor = [UIColor greenColor];
    35
    36 [self.view addSubview:mySwitch];
    37
    38 [mySwitch release];
    39 }
    40
    41 - (void)didReceiveMemoryWarning {
    42 // Releases the view if it doesn't have a superview.
    43 [super didReceiveMemoryWarning];
    44
    45 // Release any cached data, images, etc that aren't in use.
    46 }
    47
    48 - (void)viewDidUnload {
    49 // Release any retained subviews of the main view.
    50 // e.g. self.myOutlet = nil;
    51 }
    52
    53
    54 - (void)dealloc {
    55 [super dealloc];
    56 }
    57
    58 @end
  • 相关阅读:
    团队冲刺第五天
    每日学习
    团队冲刺第四天
    团队冲刺第三天
    每日学习
    2021.4.12
    2021.4.10
    2021.3.18
    2021.3.15
    2021.3.14
  • 原文地址:https://www.cnblogs.com/foxmin/p/2393641.html
Copyright © 2011-2022 走看看