UIView常用属性及方法
常用属性
NSInteger tag;
CGRect frame;
CGRect bounds;
CGPoint center;
CGAffineTransform transform;
BOOL multipleTouchEnable;
BOOL exclusiveTouch;
UIView *superView;
NSArray *subViews;
UIWindow *window;
UIColor *backgroundColor;
CGFloat alpa;
BOOL opaque;
BOOL hidden;
常用方法
类方法
1
+ (id )initWithFrame:(CGRect )frame;
实例方法
1
2
3
4
5
6
- (void) removeFromSuperview;
- (void) insertSubview:(UIView *) view atIndex:(NSInteger ) index;
- (void) exchangeSubviewAtIndex:(NSInteger ) index1 withSubviewAtIndex:(NSInteger ) index2;
- (void) addSubview:(UIView *) view;
- (void) insertSubview:(UIView *) view belowSubview:(UIView *) siblingSubview;
- (void) insertSubview:(UIView *) view aboveSubview:(UIView *) siblingSubview;
UIView常见子类
UIControl
常用属性
BOOL enable;
BOOL selected;
BOOL highlighted;
UIControlState state;<readonly
>
BOOL touchInside;<readonly
>
实例方法
1
2
3
4
- (void) addTarget:(id) target action:(SEL ) action forControlEvent:(UIControlEvent ) controlEvent;
- (void) removeTarget:(id) target action:(SEL ) action forControlEvent:(UIControlEvent ) controlEvent;
- (void) sendAction:(SEL ) action to:(id) target forEvent:(UIEvent ) event;
- (void) sendActionsForControlEvents:(UIControlEvent ) controlEvents;
UIControl常见子类
常用属性
UIButtonType buttonType;<readonly
>
NSString *currentTitle;<readonly
>
UIColor *currentColor;<readonly
>
UIImage *currentImage;<readonly
>
UIImage *currentBackgroundImage;<readonly
>
NSAttributedString *currentAttributedTitle;<readonly
>
类方法
1
+ (id)buttonWithType:(UIButtonType)buttonType;
实例方法
1
2
3
4
5
6
7
8
9
10
- (void) setTitle:(NSString *) title forState:(UIControlState ) state;
- (void) setTitleColor:(UIColor *) color forState:(UIControlState ) state;
- (void) setImage:(UIImage *) image forState:(UIControlState ) state;
- (void) setBackgroundImage:(UIImage *) image forState:(UIControlState ) state;
- (void) setAttributedTitle:(NSAttributedString *) title forState:(UIControlState ) state;
- (NSString *) titleForState:(UIControlState ) state;
- (UIColor *) titleColorForState:(UIControlState ) state;
- (UIImage *) imageForState:(UIControlState ) state;
- (UIImage *) backgroundImageForState:(UIControlState ) state;
- (NSAttributedString *) attributedStringForState:(UIControlState ) state;
UISlider
常见属性
float value;
float minimumValue;
float maximumValue;
UIImage *minimumValue;
UIImage *maximumValue;
BOOL continuous;
UIColor *minimumTrackTintColor;
UIColor *maximumTrackTintColor;
UIColor *thumbTintColor;
readonly
UIImage *currentThumbImage;
UIImage *currentMinimumTrackImage;
UIImage *currentMaximumTrackImage;
实例方法
1
2
3
4
5
6
- (void) setThumbImage:(UIImage *) image forState:(UIControlState ) state;
- (void) setMinimumTrackImage:(UIImage *) image forState:(UIControlState ) state;
- (void) setMaximumTrackImage:(UIImage *) image forState:(UIControlState ) state;
- (UIImage *) thumbImage forState:(UIControlState ) state;
- (UIImage *) minimumTrackImage forState:(UIControlState ) state;
- (UIImage *) maximumTrackImage forState:(UIControlState ) state;
UITextField
常用属性
NSString *text;
UIColor *textColor;
UIFont *font;
NSTextAlignment textAlignment;
UITextBorderStyle borderStyle;
NSString *placeholder;
BOOL clearOnBeginEditing;
BOOL adjustsFontSizeToFitWidth;
CGFloat minimumFontSize;
id delegate;
UIImage *background;
UIImage *disabledBackground;
BOOL editing;
UITextFieldViewMode clearButtonMode;
UIView *leftView;
UITextFieldViewMode leftViewMode;
UIView *rightView;
UITextFieldViewMode rightViewMode;
UIView *inputView;
UIView *inputAccessoryView;
实例方法
1
2
- (void) drawPlaceholderInRect:(CGRect ) rect;
- (void) drawTextInRect:(CGRect ) rect;
UISegmentedControl
常用属性
UISegmentedControlStyle segmentedControlStyle;
NSUInteger numberOfSegments; <readonly
>
UIColor *tintColor;
NSInteger selectedSegmentIndex;
实例方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- (id) initWithItems:(NSArray *) items;
- (void) insertSegmentWithTitle:(NSString *) title atIndex:(NSUInteger ) segment animated:(BOOL ) animated;
- (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;
- (NSString *) titleForSegmentAtIndex:(NSUInteger ) segment;
- (void) setImage:(UIImage *) image forSegmentAtIndex:(NSUInteger ) segment;
- (UIImage *) imageForSegmentAtIndex:(NSUInteger ) segment;
- (void) setWidth:(CGFloat ) width forSegmentAtIndex:(NSUInteger ) segment;
- (CGFloat ) widthForSegmentAtIndex:(NSUInteger ) segment;
- (void) setEnabled:(BOOL ) enabled forSegmentAtIndex:(NSUInteger ) segment;
- (BOOL ) isEnabledForSegmentAtIndex:(NSUInteger ) segment;
- (void) setBackgroundImage:(UIImage *) backgroundImage forState:(UIControlState ) state barMetrics:(UIBarMetrics ) barMetrics;
- (UIImage *) backgroundImageForState:(UIControlState ) state barMetrics:(UIBarMetrics ) barMetrics;
UIPageControl
常用属性
NSInteger numberOfPages;
NSInteger currentPage;
BOOL hidesForSinglePage;
BOOL defersCurrentPageDisplay; //点击翻页无效
UIColor *pageIndicatorTintColor;
UIColor *currentPageIndicatorColor;
实例方法
1
2
- (void) updateCurrentPageDisplay;
- (CGSize ) sizeForNumberOfPages:(NSInteger ) pageCount;
UISwitch
常用属性
UIColor *onTintColor;
UIColor *tintColor;
UIColor *thumbColor;
UIImage *onImage;
UIImage *offImage;
BOOL on;
实例方法
1
2
- (void) initWithFrame:(CGRect ) frame;
- (void) setOn:(BOOL ) on animated:(BOOL ) animated;
UIDatePicker
常用属性
UIDatePicker datePickerMode;
NSLocale *locale;
NSTimeZone *timeZone;
NSDate *date;
NSDate *minimumDate;
NSDate *MaximumDate;
NSTimerInterval *countDownDuration;
NSInteger minuteInterval;
实例方法
1
- (void) setDate:(NSDate *) date animated:(BOOL ) animated;
UILabel
常用属性
NSString *text;
UIFont *font;
UIColor *color;
UIColor *shadowColor;
CGSize shadowOffset;
NSTextAlignment textAlignment;
NSLineBreakMode lineBreakMode;
NSAttributedString attributedText;
UIColor *highlightedTextColor;
BOOL highlighted;
BOOL userInteractionEnabled;
BOOL enabled;
NSInteger numberOfLines;
BOOL adjustsFontSizeToFitWidth;
BOOL minimumFontSize;
实例方法
1
2
- (CGRect ) textRectForBounds:(CGRect ) bounds limitedToNumberOfLines:(NSInteger ) numberOfLines;
- (void) drawTextInRect:(CGRect ) rect;
UIAlertView
常见属性
id delegate;
NSString *title;
NSString *message;
NSInteger cancelButtonIndex;
readonly
NSInteger numberOfButtons;
NSInteger firstOtherButtonIndex;
BOOL visible;
UIAlertViewStyle alertViewStyle;
实例方法
1
2
3
4
- (id) initWithTitle:(NSString *) title message:(NSString *) message delegate:(id /*<UIAlertViewDelegate >*/) delegate cancelButtonTitle:(NSString *) cancelButtonTitle otherButtonTitles:(NSString *) otherButtonTitles, ... ;
- (void) show;
- (void) dismissWithClickEdButtonIndex:(NSInteger ) buttonIndex animated:(BOOL ) animated;
- (UITextField *) textFieldAtIndex:(NSInteger ) textFieldIndex;
UIActionSheet
常见属性
id delegate;
NSString *title;
UIActionSheetStyle actionSheetStyle;
NSInteger cancelButtonIndex;
NSInteger destructiveButtonIndex;
readonly
NSInteger numberOfButtons;
NSInteger firstOtherButtonIndex;
BOOL visible;
实例方法
1
2
3
4
5
6
7
8
9
- (id) initWithTitle:(NSString *) title delegate:(id<UIActionSheetDelegate >) delegate cancelButtonTitle:(NSString *) cancelButtonTitle destructiveButtonTitle:(NSString *) destructiveButtonTitle otherButtonTitles:(NSString *) otherButtonTitles, ... ;
- (NSInteger ) addButtonWithTitle:(NSString *) title;
- (NSString *) buttonTitleAtIndex:(NSInteger ) buttonIndex;
- (void) showFromToolbar:(UIToolBar *) view;
- (void) showFromTabBar:(UITabBar *) view;
- (void) showFromBarButtonItem:(UIBarButtonItem *) item animated:(BOOL ) animates;
- (void) showFromRect:(CGRect ) rect inView:(UIView *) view animated:(BOOL ) animated;
- (void) showInView:(UIView *) view;
- (void) dismissWithClickedButtonIndex:(NSInteger ) buttonIndex animated:(BOOL ) animated;
UIImageView
常用属性
UIImage *image;
UIImage *highlightedImage;
BOOL userInteractionEnable;
BOOL highlighted;
NSArray *animationImages;
NSArray *highlightedAnimationImages;
NSTimeInterval animationDuration;
NSInteger animationRepeatCount;
UIColor tintColor;
实例方法
1
2
3
4
5
- (id)initWithImage: (UIImage *)image;
- (id)initWithImage: (UIImage *)image highlightedImage: (UIImage *)highlightedImage;
- (void)startAnimating;
- (void)stopAnimating;
- (BOOL )isAnimating;
UINavigationBar
常用属性
UIBarStyle barStyle;
id delegate;
BOOL translucent;
NSArray *items;
UIColor *tintColor;
UIColor *barTintColor;
UIImage *shadowImage;
NSDictionary *titleTextAttributes;
UIImage *backIndicatorImage;
UIImage *backIndicatorTransitionMaskImage;
readonly
UINavigationItem *topItem;
UINavigationItem *backItem;
实例方法
1
2
3
4
5
6
7
8
9
- (void) pushNavigationItem:(UINavigationItem *) item animated:(BOOL ) animated;
- (UINavigationItem *) popNavigationItemAnimated:(BOOL ) animated;
- (void) setItems:(NSArray *) items animated:(BOOL ) animated;
- (void) setBackgroundImage:(UIImage *) backgroundImage forBarPosition:(UIBarPosition ) barPosition barMetrics:(UIBarMetrics ) barMetrics;
- (UIImage *) backgroundImageForBarPosition:(UIBarPosition ) barPosition barMetrics:(UIBarMetrics ) barMetrics;
- (void) setBackgroundImage:(UIImage *) backgroundImage forBarMetrics:(UIBarMetrics ) barMetrics NS_AVAILABLE_IOS(5 _0) ;
- (UIImage *) backgroundImageForBarMetrics:(UIBarMetrics ) barMetrics;
- (void) setTitleVerticalPositionAdjustment:(CGFloat ) adjustment forBarMetrics:(UIBarMetrics ) barMetrics;
- (CGFloat ) titleVerticalPositionAdjustmentForBarMetrics:(UIBarMetrics ) barMetrics;
UITabBar
常用属性
id delegate;
NSArray *items;
UIBarStyle barStyle
UITabBarItem *selectedItem;
UIColor *tintColor;
UIColor *barTintColor;
BOOL translucent;
UIColor *selectedImageTintColor;
UIImage *backgroundImage;
UIImage *selectionIndicatorImage;
UIImage *shadowImage;
UITabBarItemPositioning itemPositioning;
CGFloat itemWidth;
CGFloat itemSpacing;
实例方法
1
2
3
4
- (void) setItems:(NSArray *) items animated:(BOOL ) animated;
- (void) beginCustomizingItems:(NSArray *) items;
- (BOOL ) endCustomizingAnimated:(BOOL ) animated;
- (BOOL ) isCustomizing;
常用属性
UIBarStyle barStyle;
NSArray *items;
BOOL translucent;
UIColor *tintColor;
UIColor *barTintColor;
id delegate;
实例方法
1
2
3
4
5
- (void) setItems:(NSArray *) items animated:(BOOL ) animated;
- (void) setBackgroundImage:(UIImage *) backgroundImage forToolbarPosition:(UIBarPosition ) topOrBottom barMetrics:(UIBarMetrics ) barMetrics;
- (UIImage *) backgroundImageForToolbarPosition:(UIBarPosition ) topOrBottom barMetrics:(UIBarMetrics ) barMetrics;
- (void) setShadowImage:(UIImage *) shadowImage forToolbarPosition:(UIBarPosition ) topOrBottom;
- (UIImage *) shadowImageForToolbarPosition:(UIBarPosition ) topOrBottom;
UISearchBar
常用属性
UIBarStyle barStyle;
id delegate;
NSString *text;
NSString *prompt;
NSString *placeholder;
BOOL showsBookmarkButton;
BOOL showsCancelButton;
BOOL showsSearchResultsButton;
UIColor *tintColor;
UIColor *barTintColor;
UISearchBarStyle searchBarStyle;
UITextAutocapitalizationType autocapitalizationType;
UITextAutocorrectionType autocorrectionType;
UITextSpellCheckingType spellCheckingType;
UIKeyboardType keyboardType;
NSArray *scopeButtonTitles;
NSInteger selectedScopeButtonIndex;
BOOL showsScopeBar;
UIView *inputAccessoryView;
UIWebView
常用属性
id delegate;
readonly
BOOL canGoBack;
BOOL canGoForward;
BOOL loading;
UIScrollView *scrollView;
NSURLRequest *request;
实例方法
1
2
3
4
5
6
7
8
- (void) loadRequest:(NSURLRequest *) request;
- (void) loadHTMLString:(NSString *) string baseURL:(NSURL *) baseURL;
- (void) loadData:(NSData *) data MIMEType:(NSString *) MIMEType textEncodingName:(NSString *) textEncodingName baseURL:(NSURL *) baseURL;
- (void) reload;
- (void) stopLoading;
- (void) goBack;
- (void) goForward;
- (NSString *) stringByEvaluatingJavaScriptFromString:(NSString *) script;
UIPickerView
常用属性
id dataSource;
id delegate;
BOOL showsSelectionIndicator;
NSInteger numberOfComponents;<readonly
>
实例方法
1
2
3
4
5
6
7
- (NSInteger ) numberOfRowsInComponent:(NSInteger ) component;
- (CGSize ) rowSizeForComponent:(NSInteger ) component;
- (UIView *) viewForRow:(NSInteger ) row forComponent:(NSInteger ) component;
- (void) reloadAllComponents;
- (void) reloadComponent:(NSInteger ) component;
- (void) selectRow:(NSInteger ) row inComponent:(NSInteger ) component animated:(BOOL ) animated;
- (NSInteger ) selectedRowInComponent:(NSInteger ) component;
UITableViewCell
常用属性
UITableViewStyle style; <readonly
>
id dataSource;
id delegate;
CGFloat rowHeight;
CGFloat sectionHeaderHeight;
CGFloat sectionFooterHeight;
CGFloat estimatedRowHeight;
CGFloat estimatedSectionHeaderHeight;
CGFloat estimatedSectionFooterHeight;
UIEdgeInsets separatorInset;
UIView *backgroundView;
BOOL editing;
BOOL allowsSelection;
BOOL allowsSelectionDuringEditing;
BOOL allowsMultipleSelection;
BOOL allowsMultipleSelectionDuringEditing;
UIView *tableHeaderView;
UIView *tableFooterView;
NSInteger sectionIndexMinimumDisplayRowCount;
UIColor *sectionIndexColor;
UIColor *sectionIndexBackgroundColor;
UIColor *sectionIndexTrackingBackgroundColor;
UITableViewCellSeparatorStyle separatorStyle;
UIColor *separatorColor;
实例方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
- (id) initWithFrame:(CGRect ) frame style:(UITableViewStyle ) style;
- (void) reloadData;
- (void) reloadSectionIndexTitles;
- (NSInteger ) numberOfSections;
- (NSInteger ) numberOfRowsInSection:(NSInteger ) section;
- (CGRect ) rectForSection:(NSInteger ) section;
- (CGRect ) rectForHeaderInSection:(NSInteger ) section;
- (CGRect ) rectForFooterInSection:(NSInteger ) section;
- (CGRect ) rectForRowAtIndexPath:(NSIndexPath *) indexPath;
- (NSIndexPath *) indexPathForRowAtPoint:(CGPoint ) point;
- (NSIndexPath *) indexPathForCell:(UITableViewCell *) cell;
- (NSArray *) indexPathsForRowsInRect:(CGRect ) rect;
- (UITableViewCell *) cellForRowAtIndexPath:(NSIndexPath *) indexPath;
- (NSArray *) visibleCells;
- (NSArray *) indexPathsForVisibleRows;
- (UITableViewHeaderFooterView *) headerViewForSection:(NSInteger ) section;
- (UITableViewHeaderFooterView *) footerViewForSection:(NSInteger ) section;
- (void) beginUpdates;
- (void) endUpdates;
- (void) insertSections:(NSIndexSet *) sections withRowAnimation:(UITableViewRowAnimation ) animation;
- (void) deleteSections:(NSIndexSet *) sections withRowAnimation:(UITableViewRowAnimation ) animation;
- (void) reloadSections:(NSIndexSet *) sections withRowAnimation:(UITableViewRowAnimation ) animation;
- (void) moveSection:(NSInteger ) section toSection:(NSInteger ) newSection;
- (void) insertRowsAtIndexPaths:(NSArray *) indexPaths withRowAnimation:(UITableViewRowAnimation ) animation;
- (void) deleteRowsAtIndexPaths:(NSArray *) indexPaths withRowAnimation:(UITableViewRowAnimation ) animation;
- (void) reloadRowsAtIndexPaths:(NSArray *) indexPaths withRowAnimation:(UITableViewRowAnimation ) animation;
- (void) moveRowAtIndexPath:(NSIndexPath *) indexPath toIndexPath:(NSIndexPath *) newIndexPath;
- (NSIndexPath *) indexPathForSelectedRow;
- (NSArray *) indexPathsForSelectedRows;
- (id) dequeueReusableCellWithIdentifier:(NSString *) identifier;
- (id) dequeueReusableCellWithIdentifier:(NSString *) identifier forIndexPath:(NSIndexPath *) indexPath;
- (id) dequeueReusableHeaderFooterViewWithIdentifier:(NSString *) identifier;
- (void) registerNib:(UINib *) nib forCellReuseIdentifier:(NSString *) identifier;
- (void) registerClass:(Class ) cellClass forCellReuseIdentifier:(NSString *) identifier;
- (void) registerNib:(UINib *) nib forHeaderFooterViewReuseIdentifier:(NSString *) identifier;
- (void) registerClass:(Class ) aClass forHeaderFooterViewReuseIdentifier:(NSString *) identifier;
UIViewController
常用属性
UIView *view;
NSString *title;
readonly
NSString *nibName;
NSBundle *nibBundle;
UIStoryboard *storyboard;
UIViewController *parentViewController;
UIViewController *presentedViewController;
UIViewController *presentingViewController
实例方法
UIViewController的常见子类
UITabBarController
常用属性
NSArray *viewControllers;
UIViewController *selectedViewController;
NSUInteger selectedIndex;
id delegate;
readonly
UITabBar *tabBar;
UINavigationController *moreNavigationController;
实例方法
1
- (void) setViewControllers:(NSArray *) viewControllers animated:(BOOL ) animated;
UINavigationController
常用属性
id delegate;
NSArray *viewControllers;
BOOL toolbarHidden;
readonly
UIViewController *topViewController;
UIViewController *visibleViewController;
UINavigationBar *navigationBar;
UIToolbar toolbar;
实例方法
1
2
3
4
5
6
7
8
- (id) initWithRootViewController:(UIViewController *) rootViewController;
- (void) pushViewController:(UIViewController *) viewController animated:(BOOL ) animated;
- (UIViewController *) popViewControllerAnimated:(BOOL ) animated;
- (NSArray *) popToViewController:(UIViewController *) viewController animated:(BOOL ) animated;
- (NSArray *) popToRootViewControllerAnimated:(BOOL ) animated;
- (void) setViewControllers:(NSArray *) viewControllers animated:(BOOL ) animated;
- (void) setNavigationBarHidden:(BOOL ) hidden animated:(BOOL ) animated;
- (void) setToolbarHidden:(BOOL ) hidden animated:(BOOL ) animated;
UITableViewController
常用属性
UITableView *tableView;
BOOL clearsSelectionOnViewWillAppear;
UIRefreshControl *refreshControl;
实例方法
1
- (id) initWithStyle:(UITableViewStyle ) style;
UIBarItem
常用属性
BOOL enable;
NSString *title;
UIImage *image;
UIImage *landscapeImagePhone;
UIEdgeInsets imageInsets;
UIEdgeInsets landscapeImagePhoneInsets;
NSInteger tag;
实例方法
1
2
- (void) setTitleTextAttributes:(NSDictionary *) attributes forState:(UIControlState ) state;
- (NSDictionary *) titleTextAttributesForState:(UIControlState ) state;
常用属性
UIBarButtonItem style;
CGFloat width;
NSSet *possibleTitles;
UIView *customView;
SEL action;
id target;
实例方法
1
2
3
4
5
6
7
- (id) initWithImage:(UIImage *) image style:(UIBarButtonItemStyle ) style target:(id) target action:(SEL ) action;
- (id) initWithImage:(UIImage *) image landscapeImagePhone:(UIImage *) landscapeImagePhone style:(UIBarButtonItemStyle ) style target:(id) target action:(SEL ) action;
- (id) initWithTitle:(NSString *) title style:(UIBarButtonItemStyle ) style target:(id) target action:(SEL ) action;
- (id) initWithBarButtonSystemItem:(UIBarButtonSystemItem ) systemItem target:(id) target action:(SEL ) action;
- (id) initWithCustomView:(UIView *) customView;
- (void) setBackgroundImage:(UIImage *) backgroundImage forState:(UIControlState ) state barMetrics:(UIBarMetrics ) barMetrics;
- (UIImage *) backgroundImageForState:(UIControlState ) state barMetrics:(UIBarMetrics ) barMetrics
UITabBarItem
常用属性
UIImage selectedImage;
NSString badgeValue;
实例方法
1
2
3
- (id) initWithTitle:(NSString *) title image:(UIImage *) image tag:(NSInteger ) tag;
- (instancetype) initWithTitle:(NSString *) title image:(UIImage *) image selectedImage:(UIImage *) selectedImage NS_AVAILABLE_IOS(7 _0) ;
- (id) initWithTabBarSystemItem:(UITabBarSystemItem ) systemItem tag:(NSInteger ) tag;
UINavigationItem
常用属性
NSSting *title;
UIBarButtonItem *backBarButtonItem;
UIView *titleView;
NSString *prompt;
BOOL hidesBackButton;
NSArray *leftBarButtonItems;
NSArray *rightBarButtonItems;
BOOL leftItemsSupplementBackButton;
UIBarButtonItem *leftBarButtonItem;
UIBarButtonItem *rightBarButtonItem;
实例方法
1
2
3
4
5
6
- (id) initWithTitle:(NSString *) title;
- (void) setHidesBackButton:(BOOL ) hidesBackButton animated:(BOOL ) animated;
- (void) setLeftBarButtonItems:(NSArray *) items animated:(BOOL ) animated;
- (void) setRightBarButtonItems:(NSArray *) items animated:(BOOL ) animated;
- (void) setLeftBarButtonItem:(UIBarButtonItem *) item animated:(BOOL ) animated;
- (void) setRightBarButtonItem:(UIBarButtonItem *) item animated:(BOOL ) animated;