当前位置:网站首页>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 capacity expansion tutorial
- The 13th week of the second semester of sophomore year
- Etcd fast cluster building
- Implementation of concurrent programming locking
- Shardingsphere JDBC < bind table > avoid join Cartesian product
- Software testing - Summary of common interface problems
- Integration of sentinel series Nacos to realize rule synchronization and persistence
- One of PowerShell optimizations: prompt beautification
- 2021.9.30学习日志-postman
- Sentinel series hot spot current limiting
猜你喜欢

AUTOSAR actual combat tutorial pdf version
![[turn] explain awk (1)__ Awk Basics_ Options_ Program segment parsing and examples](/img/65/a214d137e230b1a1190feb03660f2c.jpg)
[turn] explain awk (1)__ Awk Basics_ Options_ Program segment parsing and examples

OpenGL mosaic (VIII)

Misunderstanding of tongweb due to ease of use

Service fusing and degradation of Note Series

13 cancelendevent of a flowable end event and compensationthrowing of a compensation event

ArrayList loop removes the pit encountered

Sentinel series integrates Nacos and realizes dynamic flow control

One of PowerShell optimizations: prompt beautification

Tongweb card, tongweb card, tongweb card
随机推荐
MySQL fuzzy query and sorting by matching degree
11 signalthrowingevent and signalboundaryevent of flowable signal event
Validation set: ‘flowable-executable-process‘ | Problem: ‘flowable-servicetask-missing-implementatio
Shardingsphere JDBC < bind table > avoid join Cartesian product
Leetcode- minimum number of operations to make array elements equal - simple
Unity game optimization [Second Edition] learning record 6
Building a stand-alone version of Nacos series
Leetcode- longest continuous increasing sequence - simple
Leetcode- reverse vowels in string - simple
Leetcode- student attendance record i- simple
Byte buddy print execution time and method link tracking
Exception after repeated application redeployment on tongweb: application instance has been stopped already or outofmemoryerror:metaspace
The difference between the increment and decrement operators before and after variables i+, +i, I –, – I
Tongweb card, tongweb card, tongweb card
Leetcode planting flowers - simple
[turn] explain awk (2)_ Combining formatted output with built-in variables to realize requirements
Parallelgateway and exclusivegateway of 14 gateways
js-bom
Unity game optimization (version 2) learning record 7
Working principle of sentinel series (concept)