今天给大家列举出来UI中的一些小控件的用法。方便大的学习与使用

一些方法和属性我们能够查看API文档。不必将每一个控件的功能都记住,

由于在使用的过程中,我们能够查看API文档。方便使用,我们仅仅要记住常见的一些方法

这里列举几个样例,其它的还要靠自己在以下学习

1.分段控制器

//
// UISegmentedControl.h
// UIKit
//
// Copyright (c) 2005-2014 Apple Inc. All rights reserved.
// #import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIControl.h>
#import <UIKit/UIKitDefines.h>
#import <UIKit/UIApplication.h>
#import <UIKit/UIGeometry.h>
#import <UIKit/UIBarButtonItem.h> typedef NS_ENUM(NSInteger, UISegmentedControlStyle) {
UISegmentedControlStylePlain, // large plain
UISegmentedControlStyleBordered, // large bordered
UISegmentedControlStyleBar, // small button/nav bar style. tintable
UISegmentedControlStyleBezeled, // DEPRECATED. Do not use this style.
} NS_DEPRECATED_IOS(2_0, 7_0, "The segmentedControlStyle property no longer has any effect"); enum {
UISegmentedControlNoSegment = -1 // segment index for no selected segment
}; typedef NS_ENUM(NSInteger, UISegmentedControlSegment) {
UISegmentedControlSegmentAny = 0,
UISegmentedControlSegmentLeft = 1, // The capped, leftmost segment. Only applies when numSegments > 1.
UISegmentedControlSegmentCenter = 2, // Any segment between the left and rightmost segments. Only applies when numSegments > 2.
UISegmentedControlSegmentRight = 3, // The capped,rightmost segment. Only applies when numSegments > 1.
UISegmentedControlSegmentAlone = 4, // The standalone segment, capped on both ends. Only applies when numSegments = 1.
}; @class UIImage, UIColor; NS_CLASS_AVAILABLE_IOS(2_0) @interface UISegmentedControl : UIControl <NSCoding>
{
@private
// Note: all instance variables will become private in the future. Do not access directly.
NSMutableArray *_segments;
NSInteger _selectedSegment;
NSInteger _highlightedSegment;
UIView* _removedSegment;
UIBarStyle _barStyle;
id _appearanceStorage;
UIView *_backgroundBarView;
CGFloat _enabledAlpha;
struct {
unsigned int style:3;
unsigned int size:2;
unsigned int delegateAlwaysNotifiesDelegateOfSegmentClicks:1;
unsigned int momentaryClick:1;
unsigned int tracking:1;
unsigned int autosizeToFitSegments:1;
unsigned int isSizingToFit:1;
unsigned int autosizeText:1;
unsigned int transparentBackground:1;
unsigned int useProportionalWidthSegments:1;
unsigned int translucentBackground:1;
unsigned int appearanceNeedsUpdate:1;
} _segmentedControlFlags;
} - (instancetype)initWithItems:(NSArray *)items; // items can be NSStrings or UIImages. control is automatically sized to fit content @property(nonatomic) UISegmentedControlStyle segmentedControlStyle NS_DEPRECATED_IOS(2_0, 7_0, "The segmentedControlStyle property no longer has any effect");
@property(nonatomic,getter=isMomentary) BOOL momentary; // if set, then we don't keep showing selected state after tracking ends. default is NO
@property(nonatomic,readonly) NSUInteger numberOfSegments; // For segments whose width value is 0, setting this property to YES attempts to adjust segment widths based on their content widths. Default is NO.
@property(nonatomic) BOOL apportionsSegmentWidthsByContent NS_AVAILABLE_IOS(5_0); - (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated; // insert before segment number. 0..#segments. value pinned
- (void)insertSegmentWithImage:(UIImage *)image atIndex:(NSUInteger)segment animated:(BOOL)animated;
- (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated;
- (void)removeAllSegments; - (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment; // can only have image or title, not both. must be 0..#segments - 1 (or ignored). default is nil
- (NSString *)titleForSegmentAtIndex:(NSUInteger)segment; - (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment; // can only have image or title, not both. must be 0..#segments - 1 (or ignored). default is nil
- (UIImage *)imageForSegmentAtIndex:(NSUInteger)segment; - (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment; // set to 0.0 width to autosize. default is 0.0
- (CGFloat)widthForSegmentAtIndex:(NSUInteger)segment; - (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment; // adjust offset of image or text inside the segment. default is (0,0)
- (CGSize)contentOffsetForSegmentAtIndex:(NSUInteger)segment; - (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment; // default is YES
- (BOOL)isEnabledForSegmentAtIndex:(NSUInteger)segment; // ignored in momentary mode. returns last segment pressed. default is UISegmentedControlNoSegment until a segment is pressed
// the UIControlEventValueChanged action is invoked when the segment changes via a user event. set to UISegmentedControlNoSegment to turn off selection
@property(nonatomic) NSInteger selectedSegmentIndex; /* Default tintColor is nil. The tintColor is inherited through the superview hierarchy. See UIView for more information.
*/
@property(nonatomic,retain) UIColor *tintColor; /* If backgroundImage is an image returned from -[UIImage resizableImageWithCapInsets:] the cap widths will be calculated from that information, otherwise, the cap width will be calculated by subtracting one from the image's width then dividing by 2. The cap widths will also be used as the margins for text placement. To adjust the margin use the margin adjustment methods. In general, you should specify a value for the normal state to be used by other states which don't have a custom value set. Similarly, when a property is dependent on the bar metrics, be sure to specify a value for UIBarMetricsDefault.
In the case of the segmented control, appearance properties for UIBarMetricsCompact are only respected for segmented controls in the smaller navigation and toolbars.
*/
- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (UIImage *)backgroundImageForState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; /* To customize the segmented control appearance you will need to provide divider images to go between two unselected segments (leftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal), selected on the left and unselected on the right (leftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal), and unselected on the left and selected on the right (leftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected).
*/
- (void)setDividerImage:(UIImage *)dividerImage forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (UIImage *)dividerImageForLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; /* You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in NSAttributedString.h.
*/
- (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (NSDictionary *)titleTextAttributesForState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; /* For adjusting the position of a title or image within the given segment of a segmented control.
*/
- (void)setContentPositionAdjustment:(UIOffset)adjustment forSegmentType:(UISegmentedControlSegment)leftCenterRightOrAlone barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (UIOffset)contentPositionAdjustmentForSegmentType:(UISegmentedControlSegment)leftCenterRightOrAlone barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; @end
2.开关控件
<pre name="code" class="objc"><pre name="code" class="objc">#import "UISwitchVC.h"

@interface UISwitchVC ()

@end

@implementation UISwitchVC

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UISwitch *sw = [[UISwitch alloc]init];
sw.frame = CGRectMake(10, 100, 300, 30);
[sw setOn:YES animated:YES];
[self.view addSubview:sw];
[sw addTarget: self action:@selector(swClick:) forControlEvents:UIControlEventValueChanged]; // Do any additional setup after loading the view.
}
-(void)swClick:(UISwitch *)sw
{
NSLog(@"%d",sw.isOn);
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end


3.计数器
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(232, 35, 0);"><span style="color: #777997">#import </span>"UIStepperVC.h"</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(195, 89, 0);"><span style="color: #35568a">@interface</span><span style="color: #000000"> </span>UIStepperVC<span style="color: #000000"> ()</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(53, 86, 138);">@end</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(53, 86, 138);">@implementation<span style="color: #000000"> UIStepperVC</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">- (<span style="color: #35568a">void</span>)viewDidLoad {</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000">    [</span><span style="color: #35568a">super</span><span style="color: #000000"> </span>viewDidLoad<span style="color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">    <span style="color: #c35900">UIStepper</span> *stepper = [[<span style="color: #c35900">UIStepper</span> <span style="color: #587ea8">alloc</span>]<span style="color: #587ea8">init</span>];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">    stepper.<span style="color: #587ea8">frame</span> = <span style="color: #587ea8">CGRectMake</span>(<span style="color: #35568a">10</span>, <span style="color: #35568a">100</span>, <span style="color: #35568a">300</span>, <span style="color: #35568a">30</span>);</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">    stepper.<span style="color: #587ea8">minimumValue</span> = <span style="color: #35568a">1</span> ;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">    stepper.<span style="color: #587ea8">maximumValue</span> = <span style="color: #35568a">100</span>;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">    stepper.<span style="color: #587ea8">stepValue</span> = <span style="color: #35568a">2</span>;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">    [<span style="color: #35568a">self</span>.<span style="color: #587ea8">view</span> <span style="color: #587ea8">addSubview</span>:stepper];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000">    </span><span style="color: #35568a">self</span><span style="color: #000000">.</span>view<span style="color: #000000">.</span>backgroundColor<span style="color: #000000"> = [</span><span style="color: #c35900">UIColor</span><span style="color: #000000"> </span>whiteColor<span style="color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">    </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000">    [stepper </span>setBackgroundImage<span style="color: #000000">:[</span><span style="color: #c35900">UIImage</span><span style="color: #000000"> </span>imageNamed<span style="color: #000000">:</span><span style="color: #e82300">@"2"</span><span style="color: #000000">] </span>forState<span style="color: #000000">:</span>UIControlStateHighlighted<span style="color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000">    [stepper </span>addTarget<span style="color: #000000">:</span><span style="color: #35568a">self</span><span style="color: #000000"> </span>action<span style="color: #000000">:</span><span style="color: #35568a">@selector</span><span style="color: #000000">(stepperClick:) </span>forControlEvents<span style="color: #000000">:</span>UIControlEventValueChanged<span style="color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">    </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);"><span style="color: #000000">    </span>// Do any additional setup after loading the view.</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">}</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">-(<span style="color: #35568a">void</span>)stepperClick:(<span style="color: #c35900">UIStepper</span> *)step</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">    <span style="color: #587ea8">NSLog</span>(<span style="color: #e82300">@"%lf"</span>,step.<span style="color: #587ea8">value</span>);</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">}</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">- (<span style="color: #35568a">void</span>)didReceiveMemoryWarning {</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000">    [</span><span style="color: #35568a">super</span><span style="color: #000000"> </span>didReceiveMemoryWarning<span style="color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);"><span style="color: #000000">    </span>// Dispose of any resources that can be recreated.</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">}</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);">/*</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);">#pragma mark - Navigation</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36); min-height: 16px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);">// In a storyboard-based application, you will often want to do a little preparation before navigation</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);">- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);">    // Get the new view controller using [segue destinationViewController].</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);">    // Pass the selected object to the new view controller.</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);">}</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(207, 135, 36);">*/</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(53, 86, 138);">@end</p><div>
</div>

UI各种小控件的用法的更多相关文章

  1. 基于jquery 封装的 select 小控件,解决 IE6 7 8里 select 边框 高度 无法遮挡等问题

    一.基本原理 select控件在浏览器中是个永远的痛,不同的版本解析出来的可谓五花八门.主要有以下问题: 1,IE6中无法设置高度,Z INDEX永远在最上,无法被其它层遮挡 2,IE7中可以设置高度 ...

  2. iOS开发UI篇—UIScrollView控件介绍

    iOS开发UI篇—UIScrollView控件介绍 一.知识点简单介绍 1.UIScrollView控件是什么? (1)移动设备的屏幕⼤大⼩小是极其有限的,因此直接展⽰示在⽤用户眼前的内容也相当有限 ...

  3. iOS开发UI篇—UITableview控件简单介绍

    iOS开发UI篇—UITableview控件简单介绍 一.基本介绍 在众多移动应⽤用中,能看到各式各样的表格数据 . 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView,UIT ...

  4. ASP.NET-----Repeater数据控件的用法总结(转)

    一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...

  5. 怎样在Android实现桌面清理内存简单Widget小控件

    怎样在Android实现桌面清理内存简单Widget小控件 我们常常会看到类似于360.金山手机卫士一类的软件会带一个widget小控件,显示在桌面上,上面会显示现有内存大小,然后会带一个按键功能来一 ...

  6. [转载]ASP.NET-----Repeater数据控件的用法总结

    一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...

  7. {Repeater控件} Repeater控件的用法流程及实例

    一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...

  8. [WinForm]WinForm跨线程UI操作常用控件类大全

    前言 在C#开发的WinForm窗体程序开发的时候,经常会使用多线程处理一些比较耗时之类的操作.不过会有一个问题:就是涉及到跨线程操作UI元素. 相信才开始接触的人一定会遇上这个问题. 为了解决这个问 ...

  9. 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI

    [源码下载] 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI 作者:webabcd 介绍背水一战 Wind ...

随机推荐

  1. 【POJ 2417】 Discrete Logging

    [题目链接] http://poj.org/problem?id=2417 [算法] Baby-Step,Giant-Step算法 [代码] #include <algorithm> #i ...

  2. hihoCoder-1830 2018亚洲区预选赛北京赛站网络赛 C.Cheat 模拟

    题面 题意:4个人围一圈坐着,每个人13张牌,然后从第一个人开始,必须按照A-K的顺序出牌,一个人出牌后,剩下的人依次可以选择是否质疑他,例如,第一个人现在必须出8(因为按照A-K顺序轮到了),可是他 ...

  3. Python环境设置-zlib not available

    今天在Linux中安Python3的时候,出现了一个错误:zipimport.ZipImportError: can‘t decompress data; zlib not available 网上找 ...

  4. Monad 系列

    本系列是在学习Monad时在网上找到的一个老外的博客,作者是MikeHadlow,地址是mikehadlow.blogspot.com,  可惜国内访问不了.这个系列对Monad讲解的浅显易懂,而且有 ...

  5. hihoCoder挑战赛31

    #1595 : Numbers 时间限制:8000ms 单点时限:1000ms 内存限制:256MB 描述 给定n个整数常数c[1], c[2], ..., c[n]和一个整数k.现在需要给2k个整数 ...

  6. dbcp相关配置

    最近在看一些dbcp的相关内容,顺便做一下记录,免得自己给忘记了.   1. 引入dbcp (选择1.4) <dependency> <groupId>com.alibaba. ...

  7. 熟悉VS2017 和Github 第二次作业

    GIT地址 https://github.com/Astone1213 GIT用户名  Astone1213 学号后五位  62114 博客地址 https://www.cnblogs.com/AsL ...

  8. 解读:20大5G关键技术

    解读:20大5G关键技术 5G网络技术主要分为三类:核心网.回传和前传网络.无线接入网. 核心网 核心网关键技术主要包括:网络功能虚拟化(NFV).软件定义网络(SDN).网络切片和多接入边缘计算(M ...

  9. 我的第一个 Windows 窗口程序(1)

    一般来说,构建一个 Windows 程序可以分为如下几个步骤: 定义窗口类(WNDCLASS) 注册窗口类(RegisterClass) 创建窗口(CreateWindow) 更新显示窗口(Updat ...

  10. IOS:兼容ios6和低版本

    viewDidUnload在ios6开始被弃用了,所以我们在这里处理内存警告的这类问题,这个时候我们就要把相应的处理放在 didReceiveMemoryWarning中. - (void)didRe ...