国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

學習iOS開關按鈕UISwitch控件

2019-10-21 18:53:26
字體:
來源:轉載
供稿:網友

開關按鈕UISwitch
在ViewController.h里面

#import <UIKit/UIKit.h>@interface ViewController : UIViewController{  //定義一個開關控件  //作用可以進行狀態的改變  //開,關:兩種狀態可以切換  //所有UIKit框架庫中的控件均已UI開頭  //蘋果官方的控件都定義在UIKit框架庫中  UISwitch * _mySwitch;}@property(retain,nonatomic) UISwitch * mySwitch;@end

在ViewController.m里面

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController@synthesize mySwitch=_mySwitch;- (void)viewDidLoad {  [super viewDidLoad];  // Do any additional setup after loading the view, typically from a nib.  //創建一個開關對象  //繼承于UIView的  _mySwitch = [[UISwitch alloc]init];  //蘋果官方的控件的位置設置  //位置X,Y的值可以改變(100,100)  //寬度和高度值無法改變(80,40)寫了也沒有用的,不會起到作用的。默認的。  _mySwitch.frame=CGRectMake(100, 200, 180, 40);  //開關狀態設置屬性  //YES:開啟狀態  //NO:關閉狀態  _mySwitch.on=YES;  //也可以使用set函數  //[_mySwitch setOn:YES];  //設置開關狀態  //p1:狀態設置  //p2:是否開啟動畫效果  //[_mySwitch setOn:YES animated:YES];  [self.view addSubview:_mySwitch];  //設置開啟狀態的風格顏色  [_mySwitch setOnTintColor:[UIColor orangeColor]];  //設置開關圓按鈕的風格顏色  [_mySwitch setThumbTintColor:[UIColor blueColor]];  //設置整體風格顏色,按鈕的白色是整個父布局的背景顏色  [_mySwitch setTintColor:[UIColor greenColor]];  //向開關控件添加事件函數  //p1:函數實現對象  //p2:函數對象  //p3:事件響應時的事件類型UIControlEventValueChanged狀態發生變化時觸發函數  [_mySwitch addTarget:self action:@selector(swChange:) forControlEvents:UIControlEventValueChanged];}//參數傳入開關對象本身- (void) swChange:(UISwitch*) sw{  if(sw.on==YES){    NSLog(@"開關被打開");  }else{    NSLog(@"開關被關閉");  }}- (void)didReceiveMemoryWarning {  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.}@end

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北票市| 美姑县| 韩城市| 华宁县| 邵阳市| 伊金霍洛旗| 仁怀市| 安宁市| 乳源| 广饶县| 略阳县| 高密市| 铁力市| 满洲里市| 霍邱县| 疏勒县| 冷水江市| 洞头县| 张家口市| 凤凰县| 乳源| 乌鲁木齐县| 泰安市| 绥阳县| 犍为县| 北川| 息烽县| 福海县| 车致| 锦州市| 阿鲁科尔沁旗| 开江县| 高青县| 长顺县| 博爱县| 连山| 乌兰县| 万年县| 原阳县| 大冶市| 沁水县|