UISwitch Class

10
UISwitch Class Reference

description

Class reference of Uiswitch for ios.

Transcript of UISwitch Class

Page 1: UISwitch Class

UISwitch Class Reference

Page 2: UISwitch Class

Contents

UISwitch Class Reference 3Overview 3Tasks 4

Initializing the Switch Object 4Setting the Off/On State 4Customizing the Appearance of the Switch 4

Properties 5offImage 5on 5onImage 6onTintColor 6thumbTintColor 6tintColor 7

Instance Methods 7initWithFrame: 7setOn:animated: 7

Document Revision History 9

2013-09-18 | Copyright © 2013 Apple Inc. All Rights Reserved.

2

Page 3: UISwitch Class

Inherits from UIControl : UIView : UIResponder : NSObject

Conforms to NSCoding

NSCoding (UIView)

UIAppearance (UIView)

UIAppearanceContainer (UIView)

UIDynamicItem (UIView)

NSObject (NSObject)

Framework /System/Library/Frameworks/UIKit.framework

Availability Available in iOS 2.0 and later.

Companion guide “Switches”

Declared in UISwitch.h

Related sample code Audio Mixer (MixerHost)

Breadcrumb

iPhoneMixerEQGraphTest

iPhoneMultichannelMixerTest

UICatalog

OverviewYou use the UISwitch class to create and manage the On/Off buttons used, for example, in the Settings appfor options such as Airplane Mode and Bluetooth. These objects are known as switches.

The UISwitch class declares a property and a method to control its on/off state. As with UISlider, whenthe user manipulates the switch control (“flips” it) a UIControlEventValueChanged event is generated,which results in the control (if properly configured) sending an action message.

You can customize the appearance of the switch by changing the color used to tint the switch when it is onor off.

2013-09-18 | Copyright © 2013 Apple Inc. All Rights Reserved.

3

UISwitch Class Reference

Page 4: UISwitch Class

For information about basic view behaviors, see View Programming Guide for iOS .

For more information about appearance and behavior configuration, see “Switches”.

Tasks

Initializing the Switch Object

– initWithFrame: (page 7)Returns an initialized switch object.

Setting the Off/On State

on (page 5) propertyA Boolean value that determines the off/on state of the switch.

– setOn:animated: (page 7)Set the state of the switch to On or Off, optionally animating the transition.

Customizing the Appearance of the Switch

onTintColor (page 6) propertyThe color used to tint the appearance of the switch when it is turned on.

tintColor (page 7) propertyThe color used to tint the outline of the switch when it is turned off.

thumbTintColor (page 6) propertyThe color used to tint the appearance of the thumb.

onImage (page 6) propertyThe image displayed when the switch is in the on position.

offImage (page 5) propertyThe image displayed while the switch is in the off position.

UISwitch Class ReferenceTasks

2013-09-18 | Copyright © 2013 Apple Inc. All Rights Reserved.

4

Page 5: UISwitch Class

Properties

offImage

The image displayed while the switch is in the off position.

@property(nonatomic, retain) UIImage *offImage

DiscussionIn iOS 7, this property has no effect.

In iOS 6, this image represents the interior contents of the switch. The image you specify is composited withthe switch’s rounded bezel and thumb to create the final appearance.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUISwitch.h

on

A Boolean value that determines the off/on state of the switch.

@property(nonatomic, getter=isOn) BOOL on

DiscussionThis property allows you to retrieve and set (without animation) a value determining whether the UISwitchobject is on or off.

AvailabilityAvailable in iOS 2.0 and later.

Related Sample CodeAVMovieExporterBTLE Central Peripheral TransferGeocoderDemooalTouchUICatalog

Declared inUISwitch.h

UISwitch Class ReferenceProperties

2013-09-18 | Copyright © 2013 Apple Inc. All Rights Reserved.

5

Page 6: UISwitch Class

onImage

The image displayed when the switch is in the on position.

@property(nonatomic, retain) UIImage *onImage

DiscussionIn iOS 7, this property has no effect.

In iOS 6, this image represents the interior contents of the switch. The image you specify is composited withthe switch’s rounded bezel and thumb to create the final appearance.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUISwitch.h

onTintColor

The color used to tint the appearance of the switch when it is turned on.

@property(nonatomic, retain) UIColor *onTintColor

AvailabilityAvailable in iOS 5.0 and later.

Declared inUISwitch.h

thumbTintColor

The color used to tint the appearance of the thumb.

@property(nonatomic, retain) UIColor *thumbTintColor

AvailabilityAvailable in iOS 6.0 and later.

Declared inUISwitch.h

UISwitch Class ReferenceProperties

2013-09-18 | Copyright © 2013 Apple Inc. All Rights Reserved.

6

Page 7: UISwitch Class

tintColor

The color used to tint the outline of the switch when it is turned off.

@property(nonatomic, retain) UIColor *tintColor

AvailabilityAvailable in iOS 6.0 and later.

Declared inUISwitch.h

Instance Methods

initWithFrame:

Returns an initialized switch object.

- (id)initWithFrame:(CGRect)frame

Parametersframe

A rectangle defining the frame of the UISwitch object. The size components of this rectangle are ignored.

Return ValueAn initialized UISwitch object or nil if the object could not be initialized.

DiscussionUISwitch overrides initWithFrame: and enforces a size appropriate for the control.

AvailabilityAvailable in iOS 2.0 and later.

Declared inUISwitch.h

setOn:animated:

Set the state of the switch to On or Off, optionally animating the transition.

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

UISwitch Class ReferenceInstance Methods

2013-09-18 | Copyright © 2013 Apple Inc. All Rights Reserved.

7

Page 8: UISwitch Class

Parameterson

YES if the switch should be turned to the On position; NO if it should be turned to the Off position. If theswitch is already in the designated position, nothing happens.

animatedYES to animate the “flipping” of the switch; otherwise NO.

DiscussionSetting the switch to either position does not result in an action message being sent.

AvailabilityAvailable in iOS 2.0 and later.

Declared inUISwitch.h

UISwitch Class ReferenceInstance Methods

2013-09-18 | Copyright © 2013 Apple Inc. All Rights Reserved.

8

Page 9: UISwitch Class

This table describes the changes to UISwitch Class Reference .

NotesDate

Updated for iOS 7.2013-09-18

Added new methods introduced in iOS 6.2012-09-19

Updated for iOS 5.2011-10-12

Fixed a typo.2010-04-06

New document that describes the class for creating and managing theOn/Off buttons known as switches.

2008-04-18

2013-09-18 | Copyright © 2013 Apple Inc. All Rights Reserved.

9

Document Revision History

Page 10: UISwitch Class

Apple Inc.Copyright © 2013 Apple Inc.All rights reserved.

No part of this publication may be reproduced,stored in a retrieval system, or transmitted, in anyform or by any means, mechanical, electronic,photocopying, recording, or otherwise, withoutprior written permission of Apple Inc., with thefollowing exceptions: Any person is herebyauthorized to store documentation on a singlecomputer for personal use only and to printcopies of documentation for personal useprovided that the documentation containsApple’s copyright notice.

No licenses, express or implied, are granted withrespect to any of the technology described in thisdocument. Apple retains all intellectual propertyrights associated with the technology describedin this document. This document is intended toassist application developers to developapplications only for Apple-labeled computers.

Apple Inc.1 Infinite LoopCupertino, CA 95014408-996-1010

Apple, the Apple logo, and iPhone are trademarksof Apple Inc., registered in the U.S. and othercountries.

iOS is a trademark or registered trademark ofCisco in the U.S. and other countries and is usedunder license.

Even though Apple has reviewed this document,APPLE MAKES NO WARRANTY OR REPRESENTATION,EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THISDOCUMENT, ITS QUALITY, ACCURACY,MERCHANTABILITY, OR FITNESS FOR A PARTICULARPURPOSE.ASARESULT, THISDOCUMENT ISPROVIDED“AS IS,” AND YOU, THE READER, ARE ASSUMING THEENTIRE RISK AS TO ITS QUALITY AND ACCURACY.

IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,INDIRECT, SPECIAL, INCIDENTAL, ORCONSEQUENTIALDAMAGES RESULTING FROM ANY DEFECT ORINACCURACY IN THIS DOCUMENT, even if advised ofthe possibility of such damages.

THE WARRANTY AND REMEDIES SET FORTH ABOVEARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORALOR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer,agent, or employee is authorized to make anymodification, extension, or addition to this warranty.

Some states do not allow the exclusion or limitationof implied warranties or liability for incidental orconsequential damages, so the above limitation orexclusion may not apply to you. This warranty givesyou specific legal rights, and youmay also have otherrights which vary from state to state.