问题
I am looking around the Object Library in Xcode 6 for UIVisualEffectView to add a blur in Storyboard. I know how to do this programmatically, but I can't find a way to do this in the Storyboard.
Is this unavailable in the current beta, or is there a way to do this that is not so straightforward?
回答1:
iOS 8.0 Gold Master UPDATE
As of the iOS 8.0 Gold Master, Xcode now has a UIVisualEffectView available in the Objects Library. To add a UIVisualEffectView to your Storyboard, just drag it from the Objects Library, position it, and then customize it using the attributes inspector.
iOS 8.0 Beta 5 and Earlier
To add a UIVisualEffectView
in a Storyboard follow these steps:
- Create a regular, empty UIView (from the objects library)
- Set the custom class of the UIView to
UIVisualEffectView
: - Connect this new view to your code, make sure that you do not add any subviews directly to it in the Storyboard (as noted in Apple's documentation).
- Proceed with the programmatic setup (i.e. with the
contentView
).
Unfortunately, it looks like the contentView
property is not an IBOutlet and therefore cannot be set in the interface (at least in this beta). Hopefully they will change that in the next beta. I filed a bug report with Apple to be able to create a UIVisualEffectView completely in Storyboards (Open Radar for rdar://17742263).
iOS 8.0 Beta 5 and Earlier - EDIT
While you are able to add a UIVisualEffectView
to a Storyboard using the method described above, it is not possible to initialize that view from the Storyboard. In the current beta (iOS 8, Beta 3) these views should be created programmatically for any effect at all.
The UIVisualEffects GitHub Repo demonstrates an easy way to setup and use the new API in a variety of ways (repo is only in Swift though, no Objective-C code).
来源:https://stackoverflow.com/questions/24851994/xcode-6-uivisualeffectview-in-storyboard