UI各种小控件的用法
今天给大家列举出来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各种小控件的用法的更多相关文章
- 基于jquery 封装的 select 小控件,解决 IE6 7 8里 select 边框 高度 无法遮挡等问题
一.基本原理 select控件在浏览器中是个永远的痛,不同的版本解析出来的可谓五花八门.主要有以下问题: 1,IE6中无法设置高度,Z INDEX永远在最上,无法被其它层遮挡 2,IE7中可以设置高度 ...
- iOS开发UI篇—UIScrollView控件介绍
iOS开发UI篇—UIScrollView控件介绍 一.知识点简单介绍 1.UIScrollView控件是什么? (1)移动设备的屏幕⼤大⼩小是极其有限的,因此直接展⽰示在⽤用户眼前的内容也相当有限 ...
- iOS开发UI篇—UITableview控件简单介绍
iOS开发UI篇—UITableview控件简单介绍 一.基本介绍 在众多移动应⽤用中,能看到各式各样的表格数据 . 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView,UIT ...
- ASP.NET-----Repeater数据控件的用法总结(转)
一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...
- 怎样在Android实现桌面清理内存简单Widget小控件
怎样在Android实现桌面清理内存简单Widget小控件 我们常常会看到类似于360.金山手机卫士一类的软件会带一个widget小控件,显示在桌面上,上面会显示现有内存大小,然后会带一个按键功能来一 ...
- [转载]ASP.NET-----Repeater数据控件的用法总结
一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...
- {Repeater控件} Repeater控件的用法流程及实例
一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...
- [WinForm]WinForm跨线程UI操作常用控件类大全
前言 在C#开发的WinForm窗体程序开发的时候,经常会使用多线程处理一些比较耗时之类的操作.不过会有一个问题:就是涉及到跨线程操作UI元素. 相信才开始接触的人一定会遇上这个问题. 为了解决这个问 ...
- 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI
[源码下载] 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI 作者:webabcd 介绍背水一战 Wind ...
随机推荐
- NET中的池
NET中的各种池 在.NET中,常用到的池有四个:字符串拘留池.线程池 .应用程序池.数据库连接池. 字符串拘留池 在.NET中字符串是不可变对象,修改字符串变量的值会产生新的对象.为降低性能消耗及减 ...
- JavaScript:目录
ylbtech-JavaScript:目录 1. https://www.javascript.com/ 2. 1.返回顶部 1. http://www.runoob.com/js/js-functi ...
- [INS-30131] 执行安装程序验证所需的初始设置失败问题解决,windows下oracle安装步骤
[INS-30131] 执行安装程序验证所需的初始设置失败问题解决,windows下oracle安装步骤 配置: 系统:windows10 数据库:Oracle Database 12c 第 1 版 ...
- Python 之 面向对象(一)
一.dir内置函数 在标识符/数据后输入一个.,然后按下TAB键,ipython会 提示该对象能够调用的方法列表 使用内置函数dir传入标识符/数据后,可以查看对象内所有的属性及方法 #查看注释 de ...
- 最小环 hdu1599 poj1734
最小环用floyd改编. hdu1599特殊一些.要求至少有三个不同的点,并且除了起点与终点重合外,中间不能有环.有点很奇怪,最大值不能为0x3f3f3f3f. poj1374就没那么讲究. //hd ...
- 决策树构建算法之—C4.5
这个网站值得收藏一下,原文链接:http://shiyanjun.cn/archives/428.html 决策树算法的优越性在于:离散学习算法进行组合总可以表达任意复杂的布尔函数,并不受数据集的限制 ...
- ML:流形学习
很多原理性的东西需要有基础性的理解,还是篇幅过少,所以讲解的不是特别的清晰. 原文链接:http://blog.sciencenet.cn/blog-722391-583413.html 流形(man ...
- 【前端】CSS隐藏元素的方法和区别
CSS隐藏元素的方法和区别 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- 强大的JQuery链式操作风格
实例代码 <style type="text/css"> #menu {width: 300px;} .has_children {background:#555;co ...
- WEBGL学习【七】画布绘图
主要是对WEBGL的绘图部分进行了进一步加强的认识和理解 <!DOCTYPE HTML> <html lang="en"> <head> < ...