uikit

扩展UIBarButtonItem

*爱你&永不变心* 提交于 2020-12-07 11:33:33
// // WYBarButtonItem+Extension.swift // DYWX // // Created by 王武 on 2020/11/24. // import UIKit extension UIBarButtonItem { // 类方法创建UIBarButtonItem class func createBarButton(_ normalImageName: String, _ highlightImageName: String, _ size: CGSize) -> UIBarButtonItem { let btn = UIButton(type: .custom) btn.setImage(UIImage(named: normalImageName), for: .normal) btn.setImage(UIImage(named: highlightImageName), for: .highlighted) btn.frame = CGRect(origin: CGPoint.zero, size: size) return UIBarButtonItem(customView: btn) } // 实例方法创建,便利构造函数: 1.必须使用 convenience 2.在构造函数中必须使用一个设计的构造函数self

扩展UIImageView

有些话、适合烂在心里 提交于 2020-12-06 11:43:45
// // WYImageView+Kingfisher.swift // DYWX // // Created by 王武 on 2020/11/24. // import UIKit import Kingfisher extension UIImageView { public var sp: UIImageView { get { return self } } /// 1.加载网络图片 /// /// - Parameters: /// - urlStr: 图片 URL地址 /// - placeholder: 占位图 func wy_setImage(urlStr: String, placeholder: UIImage? = nil) { guard let url = URL(string: urlStr) else { print("url:|\(urlStr)|无法解析为URL类型") if let placeholder = placeholder { self.image = placeholder } return } kf.setImage(with: url, placeholder: placeholder, options: [.backgroundDecode], progressBlock: nil, completionHandler:

How to modify UIMenu for UIBarButtonItem and UIButton

白昼怎懂夜的黑 提交于 2020-12-06 04:36:00
问题 iOS 14 adds the ability to display menus upon tapping or long pressing a UIBarButtonItem or UIButton, like so: let menu = UIMenu(children: [UIAction(title: "Action", image: nil) { action in //do something }]) button.menu = menu barButtonItem = UIBarButtonItem(title: "Show Menu", image: nil, primaryAction: nil, menu: menu) This most often replaces action sheets ( UIAlertController with actionSheet style). It's really common to have a dynamic action sheet where actions are only included or may

How to modify UIMenu for UIBarButtonItem and UIButton

一个人想着一个人 提交于 2020-12-06 04:35:33
问题 iOS 14 adds the ability to display menus upon tapping or long pressing a UIBarButtonItem or UIButton, like so: let menu = UIMenu(children: [UIAction(title: "Action", image: nil) { action in //do something }]) button.menu = menu barButtonItem = UIBarButtonItem(title: "Show Menu", image: nil, primaryAction: nil, menu: menu) This most often replaces action sheets ( UIAlertController with actionSheet style). It's really common to have a dynamic action sheet where actions are only included or may

How to modify UIMenu for UIBarButtonItem and UIButton

社会主义新天地 提交于 2020-12-06 04:35:05
问题 iOS 14 adds the ability to display menus upon tapping or long pressing a UIBarButtonItem or UIButton, like so: let menu = UIMenu(children: [UIAction(title: "Action", image: nil) { action in //do something }]) button.menu = menu barButtonItem = UIBarButtonItem(title: "Show Menu", image: nil, primaryAction: nil, menu: menu) This most often replaces action sheets ( UIAlertController with actionSheet style). It's really common to have a dynamic action sheet where actions are only included or may

UIDropInteractionDelegate performDrop not called?

好久不见. 提交于 2020-12-03 18:02:56
问题 I am trying to build a simple test app to learn Drag and Drop APIs. For this question I am focusing only on the Drop scenario. I have a blank View Controller, with the safari app open (multitasking) I then try to drag an image from google onto the View Controller's view. I can drag the image from safari to my app's View Controller, but when I let go, this call below is never called: func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) This is my code:

UIDropInteractionDelegate performDrop not called?

南楼画角 提交于 2020-12-03 18:02:30
问题 I am trying to build a simple test app to learn Drag and Drop APIs. For this question I am focusing only on the Drop scenario. I have a blank View Controller, with the safari app open (multitasking) I then try to drag an image from google onto the View Controller's view. I can drag the image from safari to my app's View Controller, but when I let go, this call below is never called: func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) This is my code:

iOS 嵌套UIScrollview的滑动冲突另一种解决方案

可紊 提交于 2020-11-25 13:48:03
这篇文章主要是看了 卓同学的嵌套UIScrollview的滑动冲突解决方案 之后,我想换一种方式来实现,其实基本思想是一样的。 先说说整体结构: 一个 mainScrollView 上面有一个 bannerView 和 subScrollView , subScrollView 上面有三个 tableView ,基本就是微博个人主页的那种结构 基本思路: mainScrollView 的 scrollEnabled 设为 NO subScrollView 的 scrollEnabled 设为 YES (最开始也设为NO了,但是page的实现没有想到好的方法) tableView 的 scrollEnabled 设为 NO 在 self.view 上添加 UIPanGestureRecognizer 手势 这里我们还要用到 UIDynamicAnimator 添加惯性 & 弹性动画 这样实际上 Pan 手势和 subScrollView 上的手势会冲突,但是由于两个手势控制的方向是不一样的, Pan 手势只控制垂直方向,而 subScrollView 上的手势控制水平方向,根据方向我们就可以解决手势冲突 解决手势冲突的代码 - ( BOOL ) gestureRecognizer : ( UIGestureRecognizer * ) gestureRecognizer

swift 自定义TabBarController、NavigationController复用

被刻印的时光 ゝ 提交于 2020-11-25 03:17:45
自定义TabBarController、NavigationController 简单使用(复用) 环境:xcode9.4 语言:swift4.0 git: SwiftNotes 效果图:    SLNavigationController.swift import UIKit class SLNavigationController: UINavigationController { override func viewDidLoad() { super.viewDidLoad() navigationBar.isHidden = true } /// 重写Push方法 /// 所有的push动作都会调用此方法 /// - Parameters: /// - viewController: 需要push的VC /// - animated: 是否动画 override func pushViewController(_ viewController: UIViewController, animated: Bool) { // 如果不是栈底的控制器才需要隐藏,跟控制器不需要处理 if childViewControllers.count > 0 { // 隐藏tabBar viewController.hidesBottomBarWhenPushed = true } super