[Swift]枚举类型:UIBarButtonItem的24种样式

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/ 
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:https://www.cnblogs.com/strengthen/p/10675063.html 
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

UIBarButtonSystemItemFlexibleSpace
可变空白,
在调用的过程中,使用  UIBarButtonSystemItemFlexibleSpace去占位,达到实现规范化的目的
 
UIBarButtonSystemItemFixedSpace
不可变空白 
相应的 UIBarButtonSystemItemFixedSpace则是使特定位置控件替代.
 
UIBarButtonSystemItemDone
 
 
UIBarButtonSystemItemCancel
 
 
UIBarButtonSystemItemEdit
 
 
UIBarButtonSystemItemSave
 
 
UIBarButtonSystemItemAdd
 
 
 
UIBarButtonSystemItemCompose 
 
UIBarButtonSystemItemReply
 
 
UIBarButtonSystemItemAction
 
 
UIBarButtonSystemItemOrganize
 
 
UIBarButtonSystemItemBookmarks
 
 
UIBarButtonSystemItemSearch
 
 
UIBarButtonSystemItemRefresh
 
 
UIBarButtonSystemItemStop
 
 
UIBarButtonSystemItemCamera
 
 
UIBarButtonSystemItemTrash
 
 
UIBarButtonSystemItemPlay
 
 
UIBarButtonSystemItemPause
 
 
UIBarButtonSystemItemRewind
 
 
UIBarButtonSystemItemFastForward
 
 
UIBarButtonSystemItemUndo
 
 
UIBarButtonSystemItemRedo
 
 
UIBarButtonSystemItemPageCurl NS_ENUM_DEPRECATED_IOS(4_0, 11_0)

  • IBarButtonSystemItemFlexibleSpace 和 UIBarButtonSystemItemFixedSpace不是按钮,而是调整按钮间距用的对象.让多个按钮等间距地分布在工具条中
  • 在调用的过程中,使用 UIBarButtonSystemItemFlexibleSpace去占位,达到实现规范化的目的,效果如下:
  • 不使用UIBarButtonSystemItemFlexibleSpace


     
     
  • 使用UIBarButtonSystemItemFlexibleSpace


     
     
  • UIBarButtonSystemItemFixedSpace则是替代特定位置控件,效果:


     

示例代码:
 1  override func viewDidLoad() {
 2      super.viewDidLoad()
 3      // Do any additional setup after loading the view, typically from a nib.
 4      //Prompt 属性被设置以后,其高度变为74
 5      self.navigationItem.prompt = "顶端提示"
 6      //设置导航视图标题
 7      self.title = "导航视图标题"
 8      //设置当前视图控制器的背景颜色为白色
 9      self.view.backgroundColor = UIColor.white
10      //修改导航栏背景图片(使用代码动态生成的纯色图片)
11      let image = createImageWithColor(UIColor.white,frame: CGRect(x: 0, y: 0, width: 1, height: 1))
12      self.navigationController?.navigationBar.setBackgroundImage(image, for: .default)
13      //设置背景色为不透明
14      self.navigationController?.navigationBar.isTranslucent = false
15      //设置两侧按钮颜色
16      self.navigationController?.navigationBar.tintColor = UIColor.gray
17      //设置主题颜色为黑色透明
18      self.navigationController?.navigationBar.barStyle = UIBarStyle.blackTranslucent
19      //设置左侧文件夹按钮图标,并绑定按钮点击事件
20      self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .organize,
21                                           target: self,
22                                           action: #selector(openPhotoAlbum))
23      //设置右侧相机按钮图标,并绑定按钮点击事件
24      self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .camera,
25                                            target: self,
26                                            action: #selector(ScanQRCode))
27     }
28 
29 //打开系统相册
30 @objc func openPhotoAlbum() 
31 {
32     
33 }
34 
35 //打开相机
36 @objc func ScanQRCode()
37 {
38     
39 }

 



转载于:https://www.cnblogs.com/strengthen/p/10675063.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个使用Swift语言编写的富文本编辑器用户界面的示例: ```swift import UIKit class RichTextEditorViewController: UIViewController, UITextViewDelegate { var textView: UITextView! var toolbar: UIToolbar! override func viewDidLoad() { super.viewDidLoad() // 设置文本视图 textView = UITextView(frame: view.bounds) textView.autoresizingMask = [.flexibleWidth, .flexibleHeight] textView.delegate = self view.addSubview(textView) // 设置工具栏 toolbar = UIToolbar(frame: CGRect(x: 0, y: view.bounds.height - 44, width: view.bounds.width, height: 44)) toolbar.autoresizingMask = [.flexibleWidth, .flexibleTopMargin] view.addSubview(toolbar) // 添加工具栏按钮 let boldButton = UIBarButtonItem(title: "B", style: .plain, target: self, action: #selector(boldButtonTapped)) let italicButton = UIBarButtonItem(title: "I", style: .plain, target: self, action: #selector(italicButtonTapped)) let underlineButton = UIBarButtonItem(title: "U", style: .plain, target: self, action: #selector(underlineButtonTapped)) let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) toolbar.items = [boldButton, italicButton, underlineButton, flexibleSpace] // 设置文本视图的样式 let font = UIFont.systemFont(ofSize: 16) let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: font] textView.typingAttributes = attributes } // 处理工具栏按钮的点击事件 @objc func boldButtonTapped() { let range = textView.selectedRange let existingAttributes = textView.textStorage.attributes(at: range.location, effectiveRange: nil) var newAttributes = existingAttributes newAttributes[NSAttributedString.Key.font] = UIFont.boldSystemFont(ofSize: 16) textView.textStorage.addAttributes(newAttributes, range: range) } @objc func italicButtonTapped() { let range = textView.selectedRange let existingAttributes = textView.textStorage.attributes(at: range.location, effectiveRange: nil) var newAttributes = existingAttributes newAttributes[NSAttributedString.Key.font] = UIFont.italicSystemFont(ofSize: 16) textView.textStorage.addAttributes(newAttributes, range: range) } @objc func underlineButtonTapped() { let range = textView.selectedRange let existingAttributes = textView.textStorage.attributes(at: range.location, effectiveRange: nil) var newAttributes = existingAttributes newAttributes[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.single.rawValue textView.textStorage.addAttributes(newAttributes, range: range) } // UITextViewDelegate方法 func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { // 处理删除样式 if text == "" { let existingAttributes = textView.textStorage.attributes(at: range.location, effectiveRange: nil) var newAttributes = existingAttributes newAttributes[NSAttributedString.Key.font] = UIFont.systemFont(ofSize: 16) newAttributes[NSAttributedString.Key.underlineStyle] = NSUnderlineStyle.none.rawValue textView.textStorage.addAttributes(newAttributes, range: range) } return true } } ``` 这个示例代码包括一个文本视图和一个工具

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值