diff --git a/IBProperty.podspec b/IBProperty.podspec index 35f734e..a3bb3c1 100644 --- a/IBProperty.podspec +++ b/IBProperty.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "IBProperty" - s.version = "1.1.0" + s.version = "1.1.1" s.ios.deployment_target = '7.0' s.summary = "A iOS Kit which would adapt screen by XIB and Storyboard better, and use better for XIB and Storyboard。" #s.description = <<-DESC diff --git a/IBProperty/NSLayoutConstraint+ORIBProperty.h b/IBProperty/NSLayoutConstraint+ORIBProperty.h index 19c8957..04d9631 100644 --- a/IBProperty/NSLayoutConstraint+ORIBProperty.h +++ b/IBProperty/NSLayoutConstraint+ORIBProperty.h @@ -8,6 +8,8 @@ #import +IB_DESIGNABLE + @interface NSLayoutConstraint (ORIBProperty) /* @@ -17,7 +19,7 @@ @property (nonatomic, assign) IBInspectable BOOL ib_adaptConstant; /* - * 适配导航栏高度,若为YES constant将不会适配比例,而是在iPhone X 上加上24pt, 常用于 为自定义导航栏的高度约束以及子视图布局添加约束 + * 适配导航栏高度,若为YES constant将不会适配比例,而是在iPhone X 上加上24pt, 常用于 为自定义导航栏的子视图添加约束 * constant would not adapt but add 24px in iPhone X */ @property (nonatomic, assign) IBInspectable BOOL ib_adaptXTopConstant; diff --git a/IBProperty/UICollectionViewFlowLayout+ORIBProperty.h b/IBProperty/UICollectionViewFlowLayout+ORIBProperty.h index 0a4dd16..296fe44 100644 --- a/IBProperty/UICollectionViewFlowLayout+ORIBProperty.h +++ b/IBProperty/UICollectionViewFlowLayout+ORIBProperty.h @@ -8,6 +8,8 @@ #import +IB_DESIGNABLE + @interface UICollectionViewFlowLayout (ORIBProperty) /* itemSize、minimumLineSpacing、minimumInteritemSpacing、headerReferenceSize、footerReferenceSize、sectionInset diff --git a/IBProperty/UIControl+ORIBProperty.h b/IBProperty/UIControl+ORIBProperty.h index 0fcb270..c633ae8 100644 --- a/IBProperty/UIControl+ORIBProperty.h +++ b/IBProperty/UIControl+ORIBProperty.h @@ -8,6 +8,8 @@ #import +IB_DESIGNABLE + @interface UIControl (ORIBProperty) /* diff --git a/IBProperty/UITextView+ORIBProperty.h b/IBProperty/UITextView+ORIBProperty.h index cdc88b6..643b7df 100644 --- a/IBProperty/UITextView+ORIBProperty.h +++ b/IBProperty/UITextView+ORIBProperty.h @@ -8,6 +8,8 @@ #import +IB_DESIGNABLE + @interface UITextView (ORIBProperty) /* @@ -16,5 +18,11 @@ */ @property (nonatomic, assign) IBInspectable BOOL ib_adaptFont; +/* + * 类似于UITextField的placeholder + * like UITextField's placeholder + */ +@property (nonatomic, copy) IBInspectable NSString * ib_placeholder; + @end diff --git a/IBProperty/UITextView+ORIBProperty.m b/IBProperty/UITextView+ORIBProperty.m index 1957f54..4664564 100644 --- a/IBProperty/UITextView+ORIBProperty.m +++ b/IBProperty/UITextView+ORIBProperty.m @@ -9,8 +9,14 @@ #import "UITextView+ORIBProperty.h" #import "ORIBProperty.h" +static NSInteger const placeholderTag = 2017; + @implementation UITextView (ORIBProperty) +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + - (void)setIb_adaptFont:(BOOL)ib_adaptFont { if (ib_adaptFont == YES) { @@ -22,6 +28,69 @@ - (BOOL)ib_adaptFont { return NO; } +- (void)setIb_placeholder:(NSString *)ib_placeholder { + if (ib_placeholder.length > 0) { + UILabel *label = [self viewWithTag:placeholderTag]; + if (!label) { + label = [UILabel new]; + label.font = self.font; + label.textColor = [UIColor colorWithRed:213/255.f green:213/255.f blue:213/255.f alpha:1]; + label.tag = placeholderTag; + label.frame = CGRectMake(self.textContainerInset.left + 5, self.textContainerInset.top, self.frame.size.width - (self.textContainerInset.left + self.textContainerInset.right), self.frame.size.height - (self.textContainerInset.top + self.textContainerInset.bottom)); + label.numberOfLines = 0; + [self addSubview:label]; + } + label.text = ib_placeholder; + [label sizeToFit]; + label.hidden = NO; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textBeginEditing) name:UITextViewTextDidBeginEditingNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textEndEditing) name:UITextViewTextDidEndEditingNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:nil]; + + __weak typeof (self) weakSelf = self; + + [self aspect_hookSelector:@selector(setText:) withOptions:AspectPositionAfter usingBlock:^{ + __strong typeof(weakSelf) strongSelf = weakSelf; + strongSelf.ib_plceholderLabel.hidden = strongSelf.text.length > 0 || [strongSelf isFirstResponder]; + } error:nil]; + + [self aspect_hookSelector:@selector(setTextContainerInset:) withOptions:AspectPositionAfter usingBlock:^{ + + __strong typeof(weakSelf) strongSelf = weakSelf; + + CGRect frame = strongSelf.ib_plceholderLabel.frame; + frame.origin.x = strongSelf.textContainerInset.left + 5; + frame.origin.y = strongSelf.textContainerInset.top; + strongSelf.ib_plceholderLabel.frame = frame; + } error:nil]; + + [self aspect_hookSelector:@selector(setFont:) withOptions:AspectPositionAfter usingBlock:^{ + __strong typeof(weakSelf) strongSelf = weakSelf; + strongSelf.ib_plceholderLabel.font = strongSelf.font; + } error:nil]; + } +} + +- (NSString *)ib_placeholder { + return self.ib_plceholderLabel.text; +} + +- (void)textBeginEditing { + self.ib_plceholderLabel.hidden = YES; +} + +- (void)textEndEditing { + self.ib_plceholderLabel.hidden = self.text.length > 0; +} + +- (void)textDidChange { + self.ib_plceholderLabel.hidden = self.text.length > 0 || [self isFirstResponder]; +} + +- (UILabel *)ib_plceholderLabel { + return [self viewWithTag:placeholderTag]; +} @end diff --git a/IBProperty/UIView+ORIBProperty.m b/IBProperty/UIView+ORIBProperty.m index f43b8ed..d3da216 100644 --- a/IBProperty/UIView+ORIBProperty.m +++ b/IBProperty/UIView+ORIBProperty.m @@ -23,8 +23,8 @@ - (UIImage*)imageAddib_cornerRadius:(CGFloat)radius andSize:(CGSize)size; @implementation UIImage(ORIBProperty) - (UIImage*)imageAddib_cornerRadius:(CGFloat)radius andSize:(CGSize)size{ - CGRect rect = CGRectMake(0, 0, size.width, size.height); + CGRect rect = CGRectMake(0, 0, size.width, size.height); UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale); CGContextRef ctx = UIGraphicsGetCurrentContext(); UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(radius, radius)]; @@ -59,7 +59,7 @@ - (void)setIb_borderColor:(UIColor *)ib_borderColor { } - (UIColor *)ib_borderColor { - return nil; + return [UIColor colorWithCGColor:self.layer.borderColor]; } #pragma mark -- ib_cornerRadius @@ -113,8 +113,6 @@ - (void)setIb_cornerCircle:(BOOL)ib_cornerCircle { self.layer.cornerRadius = self.bounds.size.height / 2.0f; - __weak typeof (self) weakSelf = self; - if ([self isKindOfClass:[UIImageView class]]) { [self method_exchangeWithSelector:@selector(setImage:) toSelector:@selector(ib_setImage:)]; } @@ -130,6 +128,8 @@ - (void)setIb_cornerCircle:(BOOL)ib_cornerCircle { } } + __weak typeof (self) weakSelf = self; + [self aspect_hookSelector:@selector(setBounds:) withOptions:AspectPositionAfter usingBlock:^(){ __strong typeof(weakSelf) strongSelf = weakSelf;