How to Keep IBInspectable Strings in an Array in a Custom Class Inherited from UIView

Asked 2 years ago, Updated 2 years ago, 82 views

For custom classes inherited from UIView, you can create IBInspectable properties in the following ways:

@property(strong, nonatomic) IBInspectable NSSstring*customTitle;

However, with this method, it is not possible to keep the string in the array.
For example, if you specify the following, the IB inspector will not display anything.

@property(strong, nonatomic) IBInspectable NSAray*customTitle;

How do I enable a custom view to store multiple Title strings from the IB inspector, such as UISegmentedControl?

ios objective-c xcode iphone storyboard

2022-09-29 21:12

1 Answers

Quote Apple's official documentation.

Creating a Custom View That Renders in Interface Builder

Quoted from step 12 of this:

By using the IBInspectable attribute to detail variables as
inspectable properties, you allow Interface Builder to query
render your custom view as you change the values of these properties
in the Attributes inspector.You can attach the IBInspectable
attribute to any property in a class declaration, class extension, or
category for any type that's supported by the Interface Builder
defined runtime attributes: boolean, integer or floating point number,
string, localized string, rectangle, point, size, color, range, and
nil.

In other words, IBInspectable is covered by

boolean(BOOL)
integer or floating point number (int, CGFloat, double)
US>string (NSString)
Localized string(?Unconfirmed.Sorry)
rectangle (NSRect, CGRect)
point(NSPoint, CGPoint)
size(NSSize, CGSize)
color(NSColor, UIColor)
range (NSRange)

NSArray is not covered by IBInspectable.(Probably at this time.)I don't know the future.)

引用 Although it is not mentioned in the quotation, UIImage is also IBInspectable.


2022-09-29 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.