• 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
  • 相关阅读:
    linux系统scp和rsync同步命令介绍
    linux系统发现系统变慢
    linux系统centos6和centos7开机流程及定时任务语法
    elasticsearch for windows
    elasticsearch for linux
    Python操作elasticsearch
    elasticsearch之快速上手
    elasticsearch简介
    flask中使用celery
    GoJS
  • 原文地址:https://www.cnblogs.com/foxmin/p/2393641.html
Copyright © 2020-2023  润新知