Skip to content

Commit

Permalink
v 0.4.0 加入自定义接口
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyouPrince committed Mar 4, 2020
1 parent 3e0ebe6 commit 1b51733
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,8 @@
filePath = "SectionDemo/XYInfomationSection/XYInfomationCell.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "245"
endingLineNumber = "245"
landmarkName = "-setModel:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "15B65BEC-12EB-4A1C-BD25-95C6D3B05150"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SectionDemo/XYInfomationSection/XYInfomationCell.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "394"
endingLineNumber = "394"
startingLineNumber = "302"
endingLineNumber = "302"
landmarkName = "-setModel:"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -57,8 +41,8 @@
filePath = "SectionDemo/Controller/section2/FamilyMember/FamilyMemberListViewController.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "189"
endingLineNumber = "189"
startingLineNumber = "211"
endingLineNumber = "211"
landmarkName = "-showPickerForCell:"
landmarkType = "7">
</BreakpointContent>
Expand Down
14 changes: 14 additions & 0 deletions SectionDemo/Controller/section0/BaseUseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ - (void)viewDidLoad {
// 加入数据源
[array5 addObject:item];
}


// 根据是否开启样式测试
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"open"]) {
item.titleColor = UIColor.greenColor;
item.titleFont = [UIFont systemFontOfSize:19];

item.valueColor = [UIColor cyanColor];
item.valueFont = [UIFont systemFontOfSize:25];

item.placeholderColor = [UIColor redColor];
item.placeholderFont = [UIFont systemFontOfSize:15];
}

}

section1.dataArray = array1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ - (XYInfomationSection *)section
XYInfomationItem *item7 = [XYInfomationItem modelWithTitle:@"备注信息埃菲尔无法哈维和我哈我改噶范围发哈哈尬舞个 乏味和欧发我个" titleKey:@"other" type:XYInfoCellTypeTextView value:nil placeholderValue:nil disableUserAction:NO];
item7.cellHeight = 150;



/**
测试新属性,自定义的颜色样式
*/
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"open"]) {
for (XYInfomationItem *item in @[item1,item2,item3,item4,item5,item6,item7]) {

item.titleColor = UIColor.greenColor;
item.titleFont = [UIFont systemFontOfSize:19];

item.valueColor = [UIColor yellowColor];
item.valueFont = [UIFont systemFontOfSize:25];

item.placeholderColor = [UIColor redColor];
item.placeholderFont = [UIFont systemFontOfSize:18];
}

section.separatorInset = UIEdgeInsetsMake(0, 0, 0, 30);
section.separatorColor = UIColor.redColor;
}

section.dataArray = @[item1,item2,item3,item4,item5,item6,item7];
__weak typeof(self) weakSelf = self;
section.cellClickBlock = ^(NSInteger index, XYInfomationCell * _Nonnull cell) {
Expand Down
61 changes: 58 additions & 3 deletions SectionDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ - (void)viewDidLoad {
UILabel *label3 = [[UILabel alloc] init];
label3.text = @"综合使用";

UILabel *label4 = [[UILabel alloc] init];
label4.text = @"开启试试";
UISwitch *open = [UISwitch new];
[open addTarget:self action:@selector(openValueChanged:) forControlEvents:UIControlEventValueChanged];


XYInfomationSection *section1 = [XYInfomationSection new];
XYInfomationSection *section2 = [XYInfomationSection new];
XYInfomationSection *section3 = [XYInfomationSection new];
Expand All @@ -76,6 +82,8 @@ - (void)viewDidLoad {
[self.view addSubview:label1];
[self.view addSubview:label2];
[self.view addSubview:label3];
[self.view addSubview:label4];
[self.view addSubview:open];
[self.view addSubview:section1];
[self.view addSubview:section2];
[self.view addSubview:section3];
Expand All @@ -86,6 +94,17 @@ - (void)viewDidLoad {
make.left.equalTo(self.view).offset(15);
make.right.equalTo(self.view).offset(-15);
}];

[open mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(label1).offset(0);
make.right.equalTo(self.view).offset(-15);
}];

[label4 mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(label1).offset(0);
make.right.equalTo(open.mas_left).offset(-15);
}];

[section1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(label1.mas_bottom).offset(margin);
make.left.equalTo(self.view).offset(15);
Expand Down Expand Up @@ -134,12 +153,48 @@ - (void)didClickInfoCell:(XYInfomationCell *)cell
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- (void)openValueChanged:(UISwitch *)sender
{

// NSLog(@"open = %@",sender.isOn?@"开启":@"关闭");
[[NSUserDefaults standardUserDefaults] setBool:sender.isOn forKey:@"open"];

NSMutableArray *sections = @[].mutableCopy;
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:XYInfomationSection.class]) {
[sections addObject:view];
}
}

[UIView animateWithDuration:0.1 animations:^{
for (XYInfomationSection *section in sections) {
for (XYInfomationItem *item in section.dataArray) {

if (sender.isOn) {
item.titleColor = UIColor.greenColor;
item.titleFont = [UIFont systemFontOfSize:19];

item.valueColor = [UIColor cyanColor];
item.valueFont = [UIFont systemFontOfSize:25];

item.placeholderColor = [UIColor redColor];
item.placeholderFont = [UIFont systemFontOfSize:15];
}else
{
item.titleColor = UIColor.blackColor;
item.titleFont = [UIFont systemFontOfSize:14];

item.valueColor = [UIColor blackColor];
item.valueFont = [UIFont systemFontOfSize:14];

item.placeholderColor = [UIColor lightGrayColor];
item.placeholderFont = [UIFont systemFontOfSize:14];
}
}
section.dataArray = section.dataArray;
}
}];
}


@end


Expand Down
2 changes: 2 additions & 0 deletions SectionDemo/XYInfomationSection/XYInfoTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
Set textView's placeholder text. Default is nil.
*/
@property(nullable, nonatomic,copy) IBInspectable NSString *placeholder;
@property(nullable, nonatomic,copy) UIColor *placeholderColor;
@property(nullable, nonatomic,copy) UIFont *placeholderFont;

@end

Expand Down
10 changes: 10 additions & 0 deletions SectionDemo/XYInfomationSection/XYInfoTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ -(void)setPlaceholder:(NSString *)placeholder
[self refreshPlaceholder];
}

- (void)setPlaceholderColor:(UIColor *)placeholderColor
{
placeHolderLabel.textColor = placeholderColor;
}

- (void)setPlaceholderFont:(UIFont *)placeholderFont
{
placeHolderLabel.font = placeholderFont;
}

//When any text changes on textField, the delegate getter is called. At this time we refresh the textView's placeholder
-(id<UITextViewDelegate>)delegate
{
Expand Down
20 changes: 19 additions & 1 deletion SectionDemo/XYInfomationSection/XYInfomationCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ typedef NS_ENUM(NSUInteger, XYInfoCellType) {
*/
@property(nonatomic , copy) NSString *titleKey;
/**
类型,输入还是选择 0 输入 1 选择, default is inputType
类型,输入还是选择 0 输入 1 选择 2 文本录入, default is inputType
*/
@property(nonatomic , assign) XYInfoCellType type;
/**
Expand Down Expand Up @@ -140,6 +140,24 @@ typedef NS_ENUM(NSUInteger, XYInfoCellType) {
*/
@property(nonatomic , strong) id obj;

/// 一些 cell 内部元素的 textColor, font,

/// titleColor default is #333333
@property (nonatomic, strong) UIColor *titleColor;
/// titleFont default is 15号
@property (nonatomic, strong) UIFont *titleFont;

/// valueColor default is #000000
@property (nonatomic, strong) UIColor *valueColor;
/// valueFont default is 14号
@property (nonatomic, strong) UIFont *valueFont;

/// placeholderColor default is #999999
@property (nonatomic, strong) UIColor *placeholderColor;
/// placeholderFont default is valueFont
@property (nonatomic, strong) UIFont *placeholderFont;


/// 创建方法(通过dictionary创建)
+ (instancetype)modelWithDict:(NSDictionary *)dict;

Expand Down
73 changes: 65 additions & 8 deletions SectionDemo/XYInfomationSection/XYInfomationCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,55 @@ - (CGFloat)def_cellHeight
return 50.f;
}

- (UIColor *)titleColor
{
if (!_titleColor) {
return HEXCOLOR(0x333333);
}
return _titleColor;
}

- (UIFont *)titleFont
{
if (!_titleFont) {
return [UIFont systemFontOfSize:15];
}
return _titleFont;
}

- (UIColor *)valueColor
{
if (!_valueColor) {
return HEXCOLOR(0x000000);
}
return _valueColor;
}

- (UIFont *)valueFont
{
if (!_valueFont) {
return [UIFont systemFontOfSize:14];
}
return _valueFont;
}

- (UIColor *)placeholderColor
{
if (!_placeholderColor) {
return HEXCOLOR(0x999999);
}
return _placeholderColor;
}


- (UIFont *)placeholderFont
{
if (!_placeholderFont) {
return [UIFont systemFontOfSize:14];
}
return _placeholderFont;
}

+ (instancetype)modelWithTitle:(NSString *)title
titleKey:(NSString *)titleKey
type:(XYInfoCellType)type
Expand Down Expand Up @@ -173,14 +222,22 @@ - (void)setupContent{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewTextChanged:) name:UITextViewTextDidChangeNotification object:nil];

self.backgroundColor = UIColor.clearColor;
self.titleLabel.font = [UIFont systemFontOfSize:14];
self.titleLabel.textColor = HEXCOLOR(0x999999);
self.titleLabel.font = self.model.titleFont;
self.titleLabel.textColor = self.model.titleColor;

self.inputTF.font = self.model.valueFont;
self.inputTF.textColor = self.model.valueColor;

self.inputTV.font = self.model.valueFont;
self.inputTV.textColor = self.model.valueColor;

self.detailLabel.font = self.model.valueFont;
self.detailLabel.textColor = self.model.valueColor;

self.inputTF.font = [UIFont systemFontOfSize:14];
self.inputTF.textColor = HEXCOLOR(0x333333);
UILabel *placeholderLabel = [self.inputTF valueForKey:@"placeholderLabel"];
placeholderLabel.textColor = self.model.placeholderColor;
self.inputTV.placeholderColor = self.model.placeholderColor;

self.detailLabel.font = [UIFont systemFontOfSize:14];
self.detailLabel.textColor = HEXCOLOR(0x333333);

// 添加一个底部的线
UIView *line = [UIView new];
Expand Down Expand Up @@ -360,8 +417,8 @@ - (void)setModel:(XYInfomationItem *)model
if (self.inputTF && model.disableUserAction) { // 如果是textField这种输入的情况,因为TF不能换行,这里禁用了用户操作之后,就替替换成label,这样就能正常根据文字多少进行折行操作了,也能正确展示对应的自适应高度

UILabel *label = [UILabel new];
label.font = self.inputTF.font;
label.textColor = self.inputTF.textColor;
label.font = self.model.valueFont;
label.textColor = self.model.valueColor;
label.textAlignment = NSTextAlignmentRight;
label.lineBreakMode = NSLineBreakByCharWrapping;
label.numberOfLines = 0;
Expand Down
4 changes: 4 additions & 0 deletions SectionDemo/XYInfomationSection/XYInfomationSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ typedef void(^SectionCellClickBlock)(NSInteger index,XYInfomationCell *cell);

@interface XYInfomationSection : UIView

// 需要在设置数据源之前设置,样式
@property (nonatomic) UIEdgeInsets separatorInset;
@property (nonatomic) UIColor* separatorColor;

/** dataArray : 存放XYInfomationItem对象的数据源 */
@property(nonatomic , strong) NSArray <XYInfomationItem *>*dataArray;

Expand Down
14 changes: 13 additions & 1 deletion SectionDemo/XYInfomationSection/XYInfomationSection.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,19 @@ - (void)setupContent
}
};

#warning todo - will add 组内的内距
// 添加底边和内边距
if (self.separatorColor) {
UIView *lineView = cell.subviews.lastObject;
lineView.backgroundColor = self.separatorColor;
}
if (!UIEdgeInsetsEqualToEdgeInsets(self.separatorInset, UIEdgeInsetsZero)) {
UIView *lineView = cell.subviews.lastObject;
[lineView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(lineView.superview).offset(self.separatorInset.left);
make.right.equalTo(lineView.superview).offset(-self.separatorInset.right);
}];
}

NSInteger offset = 0;
[cell mas_makeConstraints:^(MASConstraintMaker *make) {

Expand Down

0 comments on commit 1b51733

Please sign in to comment.