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
  • 相关阅读:
    Codeforces 512D
    Codeforces Gym 101480C
    Codeforces 575A
    Codeforces Round #691 (Div. 2) 题解
    .net Core 中文等非英文文字html输出编码输出问题
    .net5 grpc服务在windows上的架设方法
    北大集训 2020 游记
    北大集训2020游记
    Tricks -「网络流」经典模型汇总
    Solution -「BJWC 2018」「洛谷 P4486」Kakuro
  • 原文地址:https://www.cnblogs.com/foxmin/p/2393641.html
Copyright © 2011-2022 走看看