当前位置:网站首页>Add attributes in storyboard and Xib (fillet, foreground...) Ibinspectable and ibdesignable
Add attributes in storyboard and Xib (fillet, foreground...) Ibinspectable and ibdesignable
2022-06-13 06:01:00 【Quiet electric rod】
Here is the custom directory title
origin
iOS In development , Engineers are exposed to a lot of view rendering code . For code readability ,iOS Provides information such as xib and storyboard Tools to drag and drop controls , Set constraints . But if we need to set some Round corners , Rich text font color When waiting for attributes , Find out Xcode The attribute list provided is not available . Probably through User Defined Runtime Attributes, This is similar to what we said ***IBInspectable*** of , But it is not elegant .
IBInspectable
You can add the IBInspectable attribute to any property in a class declaration, class extension, or category of type: boolean, integer or floating point number, string, localized string, rectangle, point, size, color, range, and nil.
We can do it in class, extenstion, category Add Inspectable To modify boolean, integer or floating point number, string, localized string, rectangle, point, size, color, range, and nil Properties of type .
Objc Add attributes gracefully in
- Here, take adding fillets as an example
- Category Extended attributes
- Code instance
@interface UIView (JJIBProp)
/// radius
@property (nonatomic, assign, readwrite) IBInspectable CGFloat cornerRadius;
/// statusbar Is it hidden
@property (nonatomic, assign, readwrite) IBInspectable BOOL jjPreferedStatubarHidden;
@end
#import "UIView+JJIBProp.h"
@implementation UIView (JJIBProp)
- (void)setCornerRadius:(CGFloat)cornerRadius {
self.layer.cornerRadius = cornerRadius;
self.layer.masksToBounds = cornerRadius > 0;
}
- (CGFloat)cornerRadius {
return self.layer.cornerRadius;
}
- (BOOL)jjPreferedStatubarHidden {
return self.jjPreferedStatubarHidden;
}
- (void)setJjPreferedStatubarHidden:(BOOL)jjPreferedStatubarHidden {
[UIStatusBarManager setShouldGroupAccessibilityChildren:jjPreferedStatubarHidden];
}
Swift
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
}
IB It's probably in this style

IBDesginable
This thing can render the view directly , I know so If you want to write code for a custom view that runs only in Interface Builder, call that code from the prepareForInterfaceBuilder method. For example, while designing an app that uses the iPhone camera, you might want to draw an image that represents what the camera might capture. Interface Builder calls the prepareForInterfaceBuilder method instead of the awakeFromNib method. If you want to share code between these methods, move that code to another method that you call from both of these methods.
Raking a lot probably means : stay IB You can't get the complete information when running in , You need to prepareForInterfaceBuilder() Method , This method can be compiled with other methods , But only when the view is being prepared in Interface Builder Execute on display .
There's another way :
In Objective-C and Swift, you can use the preprocessor macro TARGET_INTERFACE_BUILDER to conditionally compile code for your custom view class.
#if !TARGET_INTERFACE_BUILDER
// Run this code only in the app
#else
// Run this code only in Interface Builder
#endif
边栏推荐
- NVIDIA Jetson Nano/Xavier NX 扩容教程
- Misunderstanding of tongweb due to ease of use
- How slow is the application system on tongweb? How dead is it?
- Mobile end adaptation scheme
- How to set the import / export template to global text format according to the framework = (solve the problem of scientific counting)
- Leetcode fizz buzz simple
- Basic application of sentinel series
- Leetcode- keyboard line - simple
- Leetcode- string addition - simple
- Concurrent programming -- source code analysis of thread pool
猜你喜欢

18 flowable task manualtask and receivetask

零拷贝技术

Test logiciel - résumé des FAQ d'interface

How MySQL optimizes the use of joint index ABC

Validation set: ‘flowable-executable-process‘ | Problem: ‘flowable-servicetask-missing-implementatio

Service fusing and degradation of Note Series

MySQL fuzzy query and sorting by matching degree
![[spark]spark introductory practical series_ 8_ Spark_ Mllib (upper)__ Introduction to machine learning and sparkmllib](/img/39/501b9b8962b03cfc59e2636f88ee93.jpg)
[spark]spark introductory practical series_ 8_ Spark_ Mllib (upper)__ Introduction to machine learning and sparkmllib

SPI primary key generation strategy for shardingsphere JDBC

You still can't remotely debug idea? Come and have a look at my article. It's easy to use
随机推荐
ffmpeg 下载后缀为.m3u8的视频文件
Some methods of string
Misunderstanding of tongweb due to ease of use
软件测试——接口常见问题汇总
Randomly fetch data from the list
Etcd fast cluster building
Experience of redis installation under Linux system (an error is reported at the same time. The struct redis server does not have a member named XXXX)
Feel the power of shardingsphere JDBC through the demo
OpenGL馬賽克(八)
Integration of sentinel series Nacos to realize rule synchronization and persistence
Three paradigms of MySQL
2021.9.29学习日志-Restful架构
Let's talk about how ArrayList is dynamically resized and what kind of mechanism is it?
MySQL custom function
2021.9.30学习日志-postman
Class conflicts caused by tongweb Enterprise Edition and embedded Edition
Leetcode- longest palindrome string - simple
为什么那么多人讨厌A-Spice
The reason why the process cannot be shut down after a spark job is executed and the solution
Leetcode- detect uppercase letters - simple