UISwitch

一、簡(jiǎn)介
<<UISwitch 的作用是給用戶提供開(kāi)關(guān),在系統(tǒng)的設(shè)置界面很常見(jiàn)

<<繼承關(guān)系:UISwitch-->UIControl-->UIView-->UIResponder-->NSObject

格式為

1-->設(shè)置開(kāi)狀態(tài)下的顏色(作用)

switch.onTintColor = [UIColor yellowColor]; (這是具體的例子)

@property(nullable, nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;(這是說(shuō)明)

二、UISwitch的屬性(屬性的順序與蘋(píng)果API一致)

1--> 設(shè)置開(kāi)狀態(tài)下的顏色

switch.onTintColor = [UIColor yellowColor];

@property(nullable, nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

2-->設(shè)置關(guān)狀態(tài)下的背景顏色

switch.tintColor = [UIColor redColor];

@property(null_resettable, nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(6_0);

3-->設(shè)置滑塊的背景顏色

switch.thumbTintColor = [UIColor blueColor];

@property(nullable, nonatomic, strong) UIColor *thumbTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;

4-->設(shè)置開(kāi)關(guān)處于開(kāi)啟狀態(tài)時(shí)的圖片(iOS7及之后設(shè)置無(wú)效)

switch.onImage = [UIImage imageNamed:@"on.png"];

@property(nullable, nonatomic, strong) UIImage *onImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
5-->設(shè)置開(kāi)關(guān)處于關(guān)閉狀態(tài)時(shí)的圖片(iOS7及之后設(shè)置無(wú)效)

switch.offImage = [UIImage imageNamed:@"off.png"];

@property(nullable, nonatomic, strong) UIImage *offImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
6--> 設(shè)置switch的開(kāi)關(guān)

swith.on = YES;

@property(nonatomic,getter=isOn) BOOL on;

7-->初始化方法

UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(50, 100, 20, 10)];

-(instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
8-->初始化方法

具體參看Objective-c 中如何重寫(xiě)父類(lèi)的初始化方法

-(nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
9-->設(shè)置開(kāi)關(guān)狀態(tài)

[switch2 setOn:YES animated:YES]

-(void)setOn:(BOOL)on animated:(BOOL)animated;

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、簡(jiǎn)介 <<UITableView(或簡(jiǎn)單地說(shuō),表視圖)的一個(gè)實(shí)例是用于顯示和編輯分層列出的信息的一種手段 <<...
    無(wú)邪8閱讀 10,957評(píng)論 3 3
  • 一、簡(jiǎn)介 <<繼承關(guān)系:UISearchBar-->UIView-->UIResponder-->NSObject...
    無(wú)邪8閱讀 1,386評(píng)論 0 1
  • // //UIView.h //UIKit // //Copyright (c) 2005-2015 Apple ...
    李某lkb閱讀 1,873評(píng)論 0 0
  • #pragma mark someValueAboutTableView 1.tableView的樣式:UITab...
    瀟巖閱讀 1,049評(píng)論 0 0
  • UIView全部API的翻譯(1) UIView是iOS系統(tǒng)界面元素的基礎(chǔ),所有的界面元素都是繼承于...
    Dear丶Musk閱讀 1,034評(píng)論 1 1

友情鏈接更多精彩內(nèi)容