IOS基础控件思维导图
image-20200729192506800.png
三、高级控件
1、UITabBarController
(1)常用属性
open var selectedIndex: Int
(2)常用方法
open func setViewControllers(_ viewControllers: [UIViewController]?, animated: Bool)
(3)内嵌控制器说明
//子视图正常情况下的图片
self.tabBarItem.image
//子视图文字
self.tabBarItem.title
//子视图在被选状态下的图片
self.tabBarItem.selectedImage
//子视图背景文字颜色
self.tabBarItem.backgroudColor
//子视图背景文字
self.tabBarItem.backgroudValue
2、UIPageViewController-->UIPageViewControllerDelegate,UIPageViewControllerDataSource
(1)常用属性
weak open var delegate: UIPageViewControllerDelegate?
weak open var dataSource: UIPageViewControllerDataSource?
(2)常用方法
//构造方法 ,第一个参数决定页面翻转的风格,第二个决定页面的方向(水平Or垂直)
public init(transitionStyle style: UIPageViewController.TransitionStyle, navigationOrientation: UIPageViewController.NavigationOrientation, options: [UIPageViewController.OptionsKey : Any]? = nil)
//添加其他的控制器到pageviewcontroller中
open func setViewControllers(_ viewControllers: [UIViewController]?, direction: UIPageViewController.NavigationDirection, animated: Bool, completion: ((Bool) -> Void)? = nil)
(3)代理方法
//改变发生前
optional func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController])
//改变发生完成时
optional func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)
//旋转方向发生改变
optional func pageViewController(_ pageViewController: UIPageViewController, spineLocationFor orientation: UIInterfaceOrientation) -> UIPageViewController.SpineLocation
(4)数据源方法
//当前controller的前一个controller是什么
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?
//当前controller的后一个controller是什么
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?
3、UINavigationController
(1)常用属性
open var isNavigationBarHidden: Bool
open var navigationBar: UINavigationBar { get }
(2)常用方法
open func pushViewController(_ viewController: UIViewController, animated: Bool)
open func popViewController(animated: Bool) -> UIViewController?
open func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]?
open func popToRootViewController(animated: Bool) -> [UIViewController]?
open var topViewController: UIViewController? { get }
4、UIAlertController+UIAlertAction
(1)UIAlertAction常用属性+方法(相当于按钮)
var isEnabled: Bool
//参数 : 1、动作的名字 2、动作的类型 3、动作执行的闭包
public convenience init(title: String?, style: UIAlertAction.Style, handler: ((UIAlertAction) -> Void)? = nil)
(2)常用属性
open var title: String?
open var message: String?
(3)常用方法
//三个参数:1、标题 2、标题下的提示信息 3、类型
public convenience init(title: String?, message: String?, preferredStyle: UIAlertController.Style)
open func addAction(_ action: UIAlertAction)
open func addTextField(configurationHandler: ((UITextField) -> Void)? = nil)
5、UITableView-->UITableViewDelegate,UITableViewDataSource
(1)常用属性
weak open var dataSource: UITableViewDataSource?
weak open var delegate: UITableViewDelegate?
open var backgroundView: UIView?
open var separatorStyle: UITableViewCell.SeparatorStyle
open var separatorColor: UIColor?
(2)常用方法
open func reloadData()
———————————————————————————————————————————————————————————————————————————————
open func rectForHeader(inSection section: Int) -> CGRect
open func rectForFooter(inSection section: Int) -> CGRect
open func rectForRow(at indexPath: IndexPath) -> CGRect
———————————————————————————————————————————————————————————————————————————————
open func insertRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)
open func deleteRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)
open func reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)
———————————————————————————————————————————————————————————————————————————————
open func insertSections(_ sections: IndexSet, with animation: UITableView.RowAnimation)
open func deleteSections(_ sections: IndexSet, with animation: UITableView.RowAnimation)
open func reloadSections(_ sections: IndexSet, with animation: UITableView.RowAnimation)
———————————————————————————————————————————————————————————————————————————————
//注册的作用是先自定义好一个cell的类,用这个类作为复用cell的模板
open func register(_ nib: UINib?, forCellReuseIdentifier identifier: String)
open func register(_ cellClass: AnyClass?, forCellReuseIdentifier identifier: String)
open func register(_ nib: UINib?, forHeaderFooterViewReuseIdentifier identifier: String)
open func register(_ aClass: AnyClass?, forHeaderFooterViewReuseIdentifier identifier: String)
(3)代理方法
optional func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
optional func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int)
optional func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int)
optional func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath)
optional func tableView(_ tableView: UITableView, didEndDisplayingHeaderView view: UIView, forSection section: Int)
optional func tableView(_ tableView: UITableView, didEndDisplayingFooterView view: UIView, forSection section: Int)
———————————————————————————————————————————————————————————————————————————————
//行高
optional func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
//头高
optional func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
//尾高
optional func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
optional func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
———————————————————————————————————————————————————————————————————————————————
optional func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath?
optional func tableView(_ tableView: UITableView, willDeselectRowAt indexPath: IndexPath) -> IndexPath?
optional func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
optional func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath)
(4)数据源方法
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
optional func numberOfSections(in tableView: UITableView) -> Int
optional func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
optional func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?
6、UICollectionView-->UICollectionViewDelegate,UICollectionViewDataSource
(1)常用属性
weak open var delegate: UICollectionViewDelegate?
weak open var dataSource: UICollectionViewDataSource?
(2)常用方法
open func reloadData()
open func insertSections(_ sections: IndexSet)
open func deleteSections(_ sections: IndexSet)
open func reloadSections(_ sections: IndexSet)
open func insertItems(at indexPaths: [IndexPath])
open func deleteItems(at indexPaths: [IndexPath])
open func reloadItems(at indexPaths: [IndexPath])
(3)代理方法
ptional func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool
optional func collectionView(_ collectionView: UICollectionView, shouldDeselectItemAt indexPath: IndexPath) -> Bool
optional func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
optional func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath)
optional func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath)
optional func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath)
(4)数据源方法
optional func numberOfSections(in collectionView: UICollectionView) -> Int
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
7、UIScrollView-->UIScrollViewDelegate
(1)常用属性
weak open var delegate: UIScrollViewDelegate?
//垂直方向滚动,默认yes
open var showsVerticalScrollIndicator: Bool
//水平方向滚动,默认yes
open var showsHorizontalScrollIndicator: Bool
open var indicatorStyle: UIScrollView.IndicatorStyle
//缩放
open var minimumZoomScale: CGFloat
open var maximumZoomScale: CGFloat
open var zoomScale: CGFloat
//scrollview所能滑动的范围,可以超过屏幕尺寸
open var contentSize: CGSize
(2)代理方法
optional func scrollViewDidScroll(_ scrollView: UIScrollView) // any offset changes
optional func scrollViewDidZoom(_ scrollView: UIScrollView) // any zoom scale changes
optional func scrollViewWillBeginDragging(_ scrollView: UIScrollView)
optional func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
optional func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)
optional func scrollViewDidScrollToTop(_ scrollView: UIScrollView) // called when scrolling animation finished. may be called immediately if already at top
网友评论