Skip to content

Commit

Permalink
FlexTextView的placeholder在重设frame后没有刷新的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenglibao committed Jun 4, 2018
1 parent ddc3c11 commit f64d58b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
**FlexLib**的所有版本的变更日志都将会在这里记录.

---
## 1.8.3
修复以下问题:
FlexTextView的placeholder在重设frame后没有刷新的问题

## 1.8.2
批量增加以下属性:
UIView::font,格式为 字体名称|字体大小 字体名称也可以是bold或者italic
Expand Down
2 changes: 1 addition & 1 deletion Example/FlexLib/res/TestLoginVC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</FlexTouchView>
<UIView layout="height:20"/>
<FlexTouchView onPress="tapTouchAction" layout="height:100,width:100%,alignItems:center,justifyContent:center" attr="bgColor:#e5e5e5,borderRadius:8,underlayColor:darkGray">
<UILabel layout="width:100%" attr="fontSize:16,textAlign:center,color:red,text:Please touch me and move\,\r\n这是测试touch功能的控件"/>
<UILabel layout="width:100%" attr="fontSize:16,textAlign:center,color:red,text:Please touch me and move\,\r\n这是测试touch功能的控件,linesNum:0"/>
</FlexTouchView>
<UIView layout="height:20"/>
<UILabel layout="width:100%" attr="fontSize:20,linesNum:0,color:#333333,text:You can press the buttons above to see the effect. We use FlexTouchView to provide more powerful function and better flexibility than button."/>
Expand Down
2 changes: 1 addition & 1 deletion Example/FlexLib/res/TextViewVC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<UIView layout="flex:1">
<UILabel attr="fontSize:16,color:#333333,text:备注"/>
<UIView layout="height:10"/>
<FlexTextView layout="width:100%,minHeight:30,maxHeight:95" attr="fontSize:16,color:#333333,text:这是一个UITextView\,你可以输入多行文本来试试效果:)"/>
<FlexTextView layout="width:100%,minHeight:30,maxHeight:95" attr="fontSize:16,color:#333333,placeholder:这是一个UITextView\,你可以输入多行文本来试试效果:)"/>
</UIView>
</UIView>

Expand Down
2 changes: 1 addition & 1 deletion FlexLib.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'FlexLib'
s.version = '1.8.2'
s.version = '1.8.3'
s.summary = 'An obj-c flex layout framework for IOS'

# This description is used to generate tags and improve search results.
Expand Down
5 changes: 4 additions & 1 deletion FlexLib/Classes/FlexContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
*/

#import "FlexContainerView.h"
#import "YogaKit/UIView+Yoga.h"

@implementation FlexContainerView

-(CGSize)sizeThatFits:(CGSize)size
{
for (UIView* subview in self.subviews) {
if(!subview.hidden){
if(!subview.hidden &&
subview.yoga.isIncludedInLayout)
{
return [super sizeThatFits:size];
}
}
Expand Down
2 changes: 2 additions & 0 deletions FlexLib/Classes/FlexTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
@property(nonatomic,nonnull,strong) NSAttributedString *attributePlaceholder;
@property(nonatomic,assign) CGPoint location;

- (void)updatePlaceholder;

@end
11 changes: 11 additions & 0 deletions FlexLib/Classes/FlexTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ - (instancetype)init
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextViewTextDidChangeNotification object:nil];

[self addObserver:self forKeyPath:@"font" options:NSKeyValueObservingOptionNew context:nil];
[self addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];

_placeholderLabel = label;
}
return self;
}
- (void)dealloc
{
[self removeObserver:self forKeyPath:@"font"];
[self removeObserver:self forKeyPath:@"frame"];

[[NSNotificationCenter defaultCenter] removeObserver:self];
}

Expand Down Expand Up @@ -167,6 +171,13 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
{
self.needAdjustFont = YES;
[self updatePlaceholder];
}else if([keyPath isEqualToString:@"frame"]){

[self updatePlaceholder];

}else{

[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}

Expand Down
17 changes: 16 additions & 1 deletion FlexLib/Classes/ViewExt/UILabel+Flex.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ @implementation UILabel (Flex)
self.font = font;
}
}
FLEXSETENUM(lineBreakMode, _breakMode)
FLEXSET(lineBreakMode)
{
NSInteger n = NSString2Int(sValue,
_breakMode,
sizeof(_breakMode)/sizeof(NameValue));
self.lineBreakMode = n;

NSMutableParagraphStyle* style=[self paraStyle];
style.lineBreakMode = n;
[self updateAttributeText];
}
FLEXSET(linesNum)
{
int n = (int)[sValue integerValue];
Expand Down Expand Up @@ -82,6 +92,10 @@ @implementation UILabel (Flex)
{
const char* c = [sValue cStringUsingEncoding:NSASCIIStringEncoding];
self.textAlignment = (NSTextAlignment)String2Int(c, _align, sizeof(_align)/sizeof(NameValue));

NSMutableParagraphStyle* style=[self paraStyle];
style.alignment = self.textAlignment;
[self updateAttributeText];
}
FLEXSET(interactEnable)
{
Expand All @@ -96,6 +110,7 @@ @implementation UILabel (Flex)
FLEXSET(value)
{
self.text = sValue;
[self updateAttributeText];
}

-(NSMutableParagraphStyle*)paraStyle
Expand Down

0 comments on commit f64d58b

Please sign in to comment.