devxoul / UITextView-Placeholder

A missing placeholder for UITextView
MIT License
1.48k stars 259 forks source link

Interface Builder support [feature-request] #13

Closed julian-weinert closed 8 years ago

julian-weinert commented 9 years ago

Since Xcode now supports IB_DESIGNABLE to identify an object needs to draw custom and IBInspectable to identify properties that can be populated to the inspector, I tried to add support myself.

IB_DESIGNABLE   // not sure if 100% needed because UITextView might be designable by default
@interface UITextView (Placeholder)
@property (nonatomic, strong) IBInspectable NSString *placeholder;
@property (nonatomic, strong) IBInspectable UIColor *placeholderColor;
@end                          ^^^^^^^^^^^^^

@implementation
#pragma mark - Interface Builder support
- (void)prepareForInterfaceBuilder {
    [super prepareForInterfaceBuilder];
    [self updatePlaceholderLabel];
}
@end

bildschirmfoto 2015-07-02 um 12 04 51

Unfortunately it does not render but since I don't have any time and am on a really tight schedule, I need to open a feature request instead of investigating my self.

Probably one would need to create custom drawing of the placeholder in - [UIViewController prepareForInterfaceBuilder]

devxoul commented 9 years ago

Hello @julian-weinert, I've struggled for several days but I couldn't find a way to make an extension's preview in Interface Builder. I think it'll be great to keep this issue opened and label 'help wanted'.

Thanks.

lastMove commented 8 years ago

I think that it's not possible, if you want to do that you will need to subclass it

julian-weinert commented 8 years ago

I did a bit research in deeper thinking of the problem. @lastMove is absolutely right. This will only work with a subclass (not a bad idea either, huh?).

Categories only make the debugger think, that an extended class implements a given method. While compiling, the categories implementation goes into the product's binary as well. The methods do not really point to the given class, but to a specific address inside the product.

Now Interface builder will scan all our headers and add the attributes marked as IBInspectable to the models. It loads classes implementations (categories are no classes) – UITextView and friends are loaded from within Xcode's Developer directory.

Given these facts, we see that IB does not load and thus not call the categories implementations.

I close this ticket, since it's technically not solvable or needs to be fixed by @Apple ;)