UIApplication
是单例模式,每个应用拥有一个唯一的UIApplication。一般用于接收系统或远程事件、通知等。
@property(class, nonatomic, readonly) UIApplication *sharedApplication;//获取当前应用
该协议用于管理UIApplication的生命周期。一切有关于应用开启、结束、挂起、激活相关的方法都定义在这个类中。
此外还涉及地理信息、健康信息、siri等内容的交互。
在iOS13后,可用新接口 UISceneDelegate 代替。
应用程序启动过程
int UIApplicationMain(int argc, char _Nullable *argv,
NSString *principalClassName, NSString *delegateClassName);
加载主界面UI文件
调用 UIApplicationDelegate 的 application:willFinishLaunchingWithOptions:
方法
加载主界面的viewController,调用相关方法
调用 UIApplicationDelegate 的 application:didFinishLaunchingWithOptions:
方法
常用方法和属性
//应用生命周期相关函数,应用构建、激活、进入后台、结束时调用
- (BOOL)application:(UIApplication *)application
willFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions;
- (void)applicationDidBecomeActive:(UIApplication *)application;
- (void)applicationWillResignActive:(UIApplication *)application;
- (void)applicationDidEnterBackground:(UIApplication *)application;
- (void)applicationWillEnterForeground:(UIApplication *)application;
- (void)applicationWillTerminate:(UIApplication *)application;
//以及相关通知
const NSNotificationName UIApplicationDidFinishLaunchingNotification;
const NSNotificationName UIApplicationDidBecomeActiveNotification;
const NSNotificationName UIApplicationDidEnterBackgroundNotification;
const NSNotificationName UIApplicationWillEnterForegroundNotification;
const NSNotificationName UIApplicationWillResignActiveNotification;
const NSNotificationName UIApplicationWillTerminateNotification;
//观察者方法,设备上锁、解锁时调用
- (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application;
- (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application;
//同时会发布通知
const NSNotificationName UIApplicationProtectedDataDidBecomeAvailable;
const NSNotificationName UIApplicationProtectedDataWillBecomeUnavailable;
//应用收到内存警告时调用,应当释放一部分资源以节省内存
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application;
const NSNotificationName UIApplicationDidReceiveMemoryWarningNotification;
UIDevice
单例模式,存储设备相关信息。包括设备名、系统信息、设备类型、设备朝向、电池信息
@property(class, nonatomic, readonly) UIDevice *currentDevice;//获取当前设备
UIStatusBarManager
用于设置手机顶部状态栏的显示、风格,获取状态栏的尺寸。
UIScreen
用于设置和获取屏幕相关属性。
@property(class, nonatomic, readonly) UIScreen *mainScreen;//获取主屏幕,单例模式
@property(nonatomic, readonly) CGRect bounds;//屏幕大小
@property(nonatomic, readonly) CGRect nativeBounds;//一般与bounds相同,但似乎在放大模式下不同
@property(nonatomic, readonly) CGRect applicationFrame;//应用尺寸
@property(nonatomic, readonly) CGFloat scale;//放大倍率,即几倍屏
@property(nonatomic, readonly) CGFloat nativeScale;//似乎在放大模式下不同
@property(nullable, nonatomic, strong) UIScreenMode *currentMode;//可以修改显示的分辨率
@property(nonatomic) CGFloat brightness;//亮度
@property(nonatomic) BOOL wantsSoftwareDimming;//柔光模式?
//获取焦点
@property(nullable, nonatomic, weak, readonly) id<UIFocusItem> focusedItem;
@property(nullable, nonatomic, weak, readonly) UIView *focusedView;
//屏幕变化相关通知
const NSNotificationName UIScreenDidConnectNotification;
const NSNotificationName UIScreenDidDisconnectNotification;
const NSNotificationName UIScreenModeDidChangeNotification;
const NSNotificationName UIScreenBrightnessDidChangeNotification;
const NSNotificationName UIScreenCapturedDidChangeNotification;
UITraitCollection
用于存储手机的一些特性和UI配置。如对比度、布局方向、图片 Scale(?)、全局字体大小、色域、主题等。
是大多数控件视图的基类,定义了许多视图和控件相关的属性和方法。
//创建方法
- (instancetype)initWithFrame:(CGRect)frame;//使用CGRect,决定控件大小和位置
//标识
@property(nonatomic) NSInteger tag;
- (__kindof UIView *)viewWithTag:(NSInteger)tag;//用tag查找相应的view
//显示属性
@property(nullable, nonatomic, copy) UIColor *backgroundColor;
@property(nonatomic, getter=isHidden) BOOL hidden; //是否隐藏
@property(nonatomic) CGFloat alpha; //透明度,会影响子控件
@property(nonatomic, getter=isOpaque) BOOL opaque; //是否不透明,会影响子控件
@property(nonatomic, strong) UIColor *tintColor; //线条、字体颜色
@property(nonatomic) BOOL clipsToBounds; //截掉子视图超出边界的部分
@property(nullable, nonatomic, strong) UIView *maskView;//显示mask
@property(nonatomic, readonly, strong) CALayer *layer; //获取视图层。layer是view真正用于视觉呈现的部分。
//用户交互相关
//是否接收用户交互,当需要与该view下层的view交互时,可以禁用。此外,ImageView和Label默认禁用。
@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled;
//是否允许多点触控
@property(nonatomic, getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;
//独占所有的用户交互,屏蔽其他view的用户交互
@property(nonatomic, getter=isExclusiveTouch) BOOL exclusiveTouch;
//尺寸
@property(nonatomic) CGRect frame; //相对父控件的坐标
@property(nonatomic) CGRect bounds; //相对子控件的坐标,改变本属性会改变子控件的位置
//如果子控件和父控件完全重叠,可以将子控件的frame设置为父控件的bounds
@property(nonatomic) CGPoint center;//中心点相对父控件坐标
@property(nonatomic) CGAffineTransform transform;//仿射变换效果,包括平移、旋转、缩放
//控件操作,插入/移除子控件
@property(nullable, nonatomic, readonly) UIWindow *window; //窗口
@property(nullable, nonatomic, readonly) UIView *superview; //父视图
@property(nonatomic, readonly, copy) NSArray<__kindof UIView *> *subviews; //子控件
- (void)addSubview:(UIView *)view;
- (void)bringSubviewToFront:(UIView *)view;
- (void)sendSubviewToBack:(UIView *)view;
- (void)removeFromSuperview;
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
- (BOOL)isDescendantOfView:(UIView *)view; //判断是否是子控件或本身
//观察者方法,可以重写,在控件操作或者窗口操作是时调用
- (void)didAddSubview:(UIView *)subview;
- (void)willRemoveSubview:(UIView *)subview;
- (void)willMoveToSuperview:(UIView *)newSuperview;
- (void)didMoveToSuperview;
- (void)willMoveToWindow:(UIWindow *)newWindow;
- (void)didMoveToWindow;
//safeArea是ios11推出的新特性,会在边缘留出一些空白,保证内容不被刘海屏等遮挡
@property(nonatomic, readonly) UIEdgeInsets safeAreaInsets;
@property(nonatomic) BOOL insetsLayoutMarginsFromSafeArea; //判断是否根据safeArea调整边距
- (void)safeAreaInsetsDidChange;//观察者方法
//布局重构相关方法
- (void)layoutSubviews; //不应直接调用。当子控件有变化,重写以重构视图。
- (void)setNeedsLayout; //当需要重构视图时调用这个,下一次屏幕刷新时调用上面的方法
- (void)layoutIfNeeded; //强制更新布局
//绘图相关方法
//具体使用和布局重构相关方法类似,功能也类似
- (void)drawRect:(CGRect)rect;//不应直接调用。当图形有变化,重写以进行重绘。
- (void)setNeedsDisplay;
- (void)setNeedsDisplayInRect:(CGRect)rect;//仅刷新一部分视图
//手势识别器相关方法
- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
- (void)removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
//获取现存的识别器
@property(nullable, nonatomic, copy) NSArray<__kindof UIGestureRecognizer *> *gestureRecognizers;
//设置识别器有效性
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
//焦点相关
@property(nonatomic, readonly) BOOL canBecomeFocused;
@property(readonly, nonatomic, getter=isFocused) BOOL focused;
- (BOOL)endEditing:(BOOL)force; //使view及其下属输入框停止输入
//动画相关
//待更新
View 不显示怎么办?
检查view:
如何优雅地书写UI
一般写一个UI,如果将所有的控件的定义与布局都写在初始化或者ViewDidLoad函数中,会导致可读性差,且耦合严重。UIView建议以如下方式书写:
// UITestView.h
@interface UITestView : UIView
@end
//========================================
// UITestView.m
//将所有需要数据读写、属性配置的重要组件写在类扩展中,方便后来控制
@interface UITestView ()
@property (nonatomic, strong) UILabel *titleLabel;
//用一个contentView作为容器存放其他组件
@property (nonatomic, strong) UIView *contentView;
@end
@implementation UITestView
//初始化部分尽量精简,仅进行必要的数据传递,UI初始化封装成一个函数
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self setupUI];
}
return self;
}
//UI初始化,主要用于装载组件,不进行数据和属性的配置
//控件使用懒加载,数据和属性的配置在加载时完成
- (void)setupUI {
[self addSubview:self.contentView];
[self.contentView addSubview:self.titleLabel];
}
//控件的位置、大小等可能发生变化的属性写在layoutSubviews中
- (void)layoutSubviews {
[super layoutSubviews];
self.contentView.frame = self.bounds;
self.titleLabel.frame = ...;
if (self.showTitle) {
self.titleLabel.hidden = YES;
} else {
self.titleLabel.hidden = NO;
}
}
//懒加载
- (UIView *)contentView {
if (!_contentView) {
_contentView = [UIView new];
}
return _contentView;
}
//控件初始化,设置那些固定不变的属性
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel newWithFrame:CGRectZero];
_titleLabel.textColor = [UIColor redColor];
_titleLabel.text = @"标题";
_titleLabel.textAlignment = NSTextAlignmentLeft;
[_titleLabel sizeToFit];
}
return _titleLabel;
}
@end
是MVC模型中的C端,UIResponder的子类。ViewController是view的创建者和控制者,也是subView的创建者。
//视图加载
//当访问这个对象时,如果view没有加载,会触发懒加载
@property(nonatomic, strong) UIView *view;
//不会触发懒加载,未加载则返回nil
@property(nullable, nonatomic, readonly, strong) UIView *viewIfLoaded;
//是否已加载
@property(nonatomic, readonly, getter=isViewLoaded) BOOL viewLoaded;
//观察者方法
- (void)loadView; //可以重写,但建议重写下面的方法。需要调用super方法
- (void)viewDidLoad; //视图加载到内存后调用,如果要进行额外的初始化操作则应重写,必须调用super方法
- (void)viewWillAppear:(BOOL)animated; //视图呈现之前调用,必须调用super方法
- (void)viewDidAppear:(BOOL)animated; //视图呈现之后调用,必须调用super方法
- (void)viewWillDisappear:(BOOL)animated; //必须调用super方法
- (void)viewDidDisappear:(BOOL)animated; //必须调用super方法
//视图调整
- (void)viewWillLayoutSubviews;
- (void)viewDidLayoutSubviews;
//navigationBar与tabBar相关属性
@property(nonatomic, readonly, strong) UINavigationItem *navigationItem;
@property(nonatomic) BOOL hidesBottomBarWhenPushed;
@property(nullable, nonatomic, strong) NSArray<__kindof UIBarButtonItem *> *toolbarItems;
- (void)setToolbarItems:(NSArray<UIBarButtonItem *> *)toolbarItems animated:(BOOL)animated;
@property(nonatomic, strong) UITabBarItem *tabBarItem;
//状态栏相关
@property(nonatomic, readonly) UIStatusBarStyle preferredStatusBarS
@property(nonatomic, readonly) BOOL prefersStatusBarHidden;
- (void)setNeedsStatusBarAppearanceUpdate;
//跳转到新视图、撤销一个视图
- (void)presentViewController:(UIViewController *)viewControllerToPresent
animated:(BOOL)flag
completion:(void (^)(void))completion;
- (void)dismissViewControllerAnimated:(BOOL)flag
completion:(void (^)(void))completion;
表格视图,用于呈现数据,几乎是最常用的一类控件。
@interface UITableView : UIScrollView
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
//加载数据的委托,必须实现并重写相关方法
@property(nonatomic, weak, nullable) id<UITableViewDataSource> dataSource;
//委托,用于处理生命周期和获取高度等属性
@property(nonatomic, weak, nullable) id<UITableViewDelegate> delegate;
//样式,是否以分组形式呈现表格
@property(nonatomic, readonly) UITableViewStyle style;
//视觉控件
@property(nonatomic, strong, nullable) UIView *tableHeaderView;
@property(nonatomic, strong, nullable) UIView *tableFooterView;
@property(nonatomic, strong, nullable) UIView *backgroundView;
//高度属性,控件高度动态调整时忽略这一属性
@property(nonatomic) CGFloat rowHeight;
@property(nonatomic) CGFloat sectionHeaderHeight;
@property(nonatomic) CGFloat sectionFooterHeight;
//估计行高,动态尺寸时应设置为0,否则获取尺寸时数值错误
@property(nonatomic) CGFloat estimatedRowHeight;
@property(nonatomic) CGFloat estimatedSectionHeaderHeight;
@property(nonatomic) CGFloat estimatedSectionFooterHeight;
//获取尺寸
- (CGRect)rectForSection:(NSInteger)section;
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGRect)rectForFooterInSection:(NSInteger)section;
- (CGRect)rectForHeaderInSection:(NSInteger)section;
//分割线属性
@property(nonatomic) UITableViewCellSeparatorStyle separatorStyle;
@property(nonatomic, strong, nullable) UIColor *separatorColor;
@property(nonatomic) UIEdgeInsets separatorInset;
//单元格重用
- (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier
forIndexPath:(NSIndexPath *)indexPath;
- (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;
- (__kindof UITableViewHeaderFooterView *)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier;
//单元格选中相关操作
@property(nonatomic, readonly, nullable) NSIndexPath *indexPathForSelectedRow;
@property(nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForSelectedRows;
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath
animated:(BOOL)animated
scrollPosition:(UITableViewScrollPosition)scrollPosition;
//重新载入数据
@property(nonatomic, readonly) BOOL hasUncommittedUpdates;//是否含有未提交的改变
- (void)reloadData; //需要刷新数据时调用此方法
- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadSections:(NSIndexSet *)sections
withRowAnimation:(UITableViewRowAnimation)animation;
//拖拽相关
//拖拽委托,用于管理拖拽行为的生命周期
@property(nonatomic, weak, nullable) id<UITableViewDragDelegate> dragDelegate;
@property(nonatomic, readonly) BOOL hasActiveDrag; //是否有正在拖拽的单元格
@property(nonatomic) BOOL dragInteractionEnabled; //是否允许拖拽,iPhone上默认为NO
//滚动方法
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
atScrollPosition:(UITableViewScrollPosition)scrollPosition
animated:(BOOL)animated;
- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition
animated:(BOOL)animated;
//编辑(插入删除)相关
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;//进入编辑状态
@property(nonatomic, getter=isEditing) BOOL editing; //是否处于编辑状态
UITableView获取数据的协议,系统会在合适的时机自动调用方法.
//获取特定组中的行数
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section;
//获取组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
//获取单元格,核心逻辑,必须重写且不可返回nil。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath;
//获取每组的标题
//当定义了viewForHeaderInSection方法时,该方法无效
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section;
//获取每组的尾部标题
- (NSString *)tableView:(UITableView *)tableView
titleForFooterInSection:(NSInteger)section;
//屏幕右边的分组目录
- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView;
//根据标题和索引获取分组位置
- (NSInteger)tableView:(UITableView *)tableView
sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
//是否允许单元格编辑(删除、插入)
- (BOOL)tableView:(UITableView *)tableView
canEditRowAtIndexPath:(NSIndexPath *)indexPath;
//要启用单元格的滑动删除功能必须重写该方法
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath;
//单元格是否可移动
- (BOOL)tableView:(UITableView *)tableView
canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
//移动单元格
- (void)tableView:(UITableView *)tableView
moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath
toIndexPath:(NSIndexPath *)destinationIndexPath;
UITableView委托,用于处理生命周期,获取高度等属性。
- (void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
//设置单元格缩进
- (NSInteger)tableView:(UITableView *)tableView
indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath;
//当选中一个单元格时,可以同时选中/取消选中另一个
- (NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)tableView:(UITableView *)tableView
willDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
//生命周期管理
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView
didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView
willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section;
- (void)tableView:(UITableView *)tableView
willDisplayFooterView:(UIView *)view forSection:(NSInteger)section;
- (void)tableView:(UITableView *)tableView
didEndDisplayingCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView
didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section;
- (void)tableView:(UITableView *)tableView
didEndDisplayingFooterView:(UIView *)view
forSection:(NSInteger)section;
//高亮管理
- (BOOL)tableView:(UITableView *)tableView
shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView
didHighlightRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView
didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath;
//编辑(删除、插入)管理
- (void)tableView:(UITableView *)tableView
willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView
didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)tableView:(UITableView *)tableView
shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;
//是否多选
- (BOOL)tableView:(UITableView *)tableView
shouldBeginMultipleSelectionInteractionAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView
didBeginMultipleSelectionInteractionAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableViewDidEndMultipleSelectionInteraction:(UITableView *)tableView;
//获取视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
//获取高度
//当单元格高度变化时重写此方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
//获取每组的高度,为0时不显示。但如果定义了viewForHeaderInSection方法,为0时自适应
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
//估计控件的尺寸(高度),可以提高性能,但会导致尺寸获取错误
//动态控制控件尺寸的场合不适用
const CGFloat UITableViewAutomaticDimension;
- (CGFloat)tableView:(UITableView *)tableView
estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView
estimatedHeightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView
estimatedHeightForFooterInSection:(NSInteger)section;
tableView的控制器,一般不需要使用这个,而是直接使用UIViewController。
@property(nonatomic, strong) UITableView *tableView; //与view属性相同
//当tableView重新呈现在屏幕上时,会清空之前的选中情况,默认开启。
@property(nonatomic) BOOL clearsSelectionOnViewWillAppear;
tableView的单元格,系统提供了一系列预定义的风格和控件。
//单元格复用
//由于表格需要在屏幕上滚动,如果每一个单元格出现时都要重新创建控件会导致性能消耗过大,复用单元格可以提高性能
//OC使用队列存储可复用的单元格,使用复用标签来确定单元格是否应该被复用
//tableView调用dequeueReusableCellWithIdentifier方法进行复用
@property(nonatomic, readonly, copy, nullable) NSString *reuseIdentifier;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier;
- (void)prepareForReuse;//单元格被复用前会调用该方法
//背景相关属性
@property(nonatomic, copy, nullable) UIBackgroundConfiguration *backgroundConfiguration;
@property(nonatomic) BOOL automaticallyUpdatesBackgroundConfiguration;
@property(nonatomic, strong, nullable) UIView *backgroundView;
@property(nonatomic, strong, nullable) UIView *selectedBackgroundView;
@property(nonatomic, strong, nullable) UIView *multipleSelectionBackgroundView;
//cell内容
- (UIListContentConfiguration *)defaultContentConfiguration;
@property(nonatomic, copy, nullable) id<UIContentConfiguration> contentConfiguration;
@property(nonatomic, readonly, strong, nullable) UILabel *textLabel;
@property(nonatomic, readonly, strong, nullable) UILabel *detailTextLabel;
@property(nonatomic, readonly, strong, nullable) UIImageView *imageView;
//上面时系统内建的cell,缺少灵活性,对cell样式有要求则应自定义contentView
@property(nonatomic, readonly, strong) UIView *contentView;
//右边小图标样式
@property(nonatomic) UITableViewCellAccessoryType accessoryType;
@property(nonatomic, strong, nullable) UIView *accessoryView;
@property(nonatomic) UITableViewCellAccessoryType editingAccessoryType;
@property(nonatomic, strong, nullable) UIView *editingAccessoryView;
//选中态相关
@property(nonatomic, getter=isSelected) BOOL selected;
@property(nonatomic) UITableViewCellSelectionStyle selectionStyle;//设置被选中时的视觉状态
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
@property(nonatomic, getter=isHighlighted) BOOL highlighted;
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;
//修改状态
@property(nonatomic, getter=isEditing) BOOL editing;
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
@property(nonatomic, readonly) UITableViewCellEditingStyle editingStyle;
//缩进
@property(nonatomic) NSInteger indentationLevel;
@property(nonatomic) CGFloat indentationWidth;
@property(nonatomic) BOOL shouldIndentWhileEditing;
@property(nonatomic) UIEdgeInsets separatorInset;
评论区