ios10 - widgetPrimaryVibrancyEffect 和 widgetSecondaryVibrancyEffect

标签 ios10

widgetSecondaryVibrancyEffect 和 widgetPrimaryVibrancyEffect 之间有什么区别?

enter image description here

最佳答案

widgetPrimaryVibrancyEffect

用于选择支持文本和字形。

widgetSecondaryVibrancyEffect

用于需要进一步缩小的选择支持文本和字形

这是一个带有两个 UIButton 的插图:

enter image description here

Swift 3.0 TodayViewController(今日扩展):

import UIKit
import NotificationCenter

class TodayViewController: UIViewController, NCWidgetProviding {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view from its nib.
        self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded

        setupStackView()
    }
    private func setupStackView(){
        let stackView = UIStackView(frame: CGRect.zero)
        stackView.translatesAutoresizingMaskIntoConstraints = false
        stackView.alignment = .fill
        stackView.axis      = .vertical
        stackView.distribution  = .fillEqually

        self.view.addSubview(stackView)

        let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|[stackView]|", options: NSLayoutFormatOptions(rawValue:0), metrics: nil, views: ["stackView":stackView])
        let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|[stackView]|", options: NSLayoutFormatOptions(rawValue:0), metrics: nil, views: ["stackView":stackView])

        self.view.addConstraints(hConstraints)
        self.view.addConstraints(vConstraints)


        stackView.addArrangedSubview(self.effectView(withEffect: UIVibrancyEffect.widgetPrimary(),   andButtonTitle: "widgetPrimaryVibrancyEffect"))
        stackView.addArrangedSubview(self.effectView(withEffect: UIVibrancyEffect.widgetSecondary(), andButtonTitle: "widgetSecondaryVibrancyEffect"))
    }

    private func effectView(withEffect effect : UIVisualEffect, andButtonTitle title : String)->UIVisualEffectView{
        //Create button
        let button = UIButton(type: .custom)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.setTitle(title, for: .normal)

        //Create UIVisualEffectView
        let effectView = UIVisualEffectView(effect:  effect)
        effectView.frame = CGRect.zero
        effectView.translatesAutoresizingMaskIntoConstraints = false


        effectView.contentView.addSubview(button)

        //Constraints
        button.leftAnchor.constraint(equalTo: effectView.contentView.leftAnchor).isActive = true
        button.topAnchor.constraint(equalTo: effectView.contentView.topAnchor).isActive = true
        button.rightAnchor.constraint(equalTo: effectView.contentView.rightAnchor).isActive = true
        button.bottomAnchor.constraint(equalTo: effectView.contentView.bottomAnchor).isActive = true

        return effectView
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func widgetPerformUpdate(completionHandler: ((NCUpdateResult) -> Void)) {
        completionHandler(NCUpdateResult.newData)
    }

}

关于ios10 - widgetPrimaryVibrancyEffect 和 widgetSecondaryVibrancyEffect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38431508/

相关文章:

xcode - Xcode 8 中的警告 : Instance method nearly matches optional requirement

objective-c - 仅 MFMailComposeViewController 和 iOS 10 的隐私问题

ios - Cordova后台模式地理位置iOS 10

ios - Xcode 8.1 和 iOS 10.1.1 无法构建

ios10 - UISwitch setOn(:, 动画:) 不能作为文档工作

ios - 我怎样才能让 UNNotificationRequest 立即弹出?

ios - 部署目标是什么意思?

iOS 10 Collection View :prefetchItemsAt not called

ios - iOS10 测试版中的 IOKit

ios - 无法将类型 'NSFetchRequest<NSFetchRequestResult>' 的值转换为指定类型 'NSFetchRequest<T>'