diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/project.pbxproj" "b/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/project.pbxproj" index 5ef47bb..91a9cfd 100644 --- "a/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/project.pbxproj" +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/project.pbxproj" @@ -47,6 +47,8 @@ 99E728A91BE5E22D00771161 /* SDRefreshHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 99E728A21BE5E22D00771161 /* SDRefreshHeaderView.m */; }; 99E728AA1BE5E22D00771161 /* SDRefreshView.m in Sources */ = {isa = PBXBuildFile; fileRef = 99E728A41BE5E22D00771161 /* SDRefreshView.m */; }; 99E728AB1BE5E22D00771161 /* UIView+SDExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 99E728A61BE5E22D00771161 /* UIView+SDExtension.m */; }; + E6FEDD781C2A7BE60088E4F0 /* DemoVC9.m in Sources */ = {isa = PBXBuildFile; fileRef = E6FEDD751C2A7BE60088E4F0 /* DemoVC9.m */; }; + E6FEDD791C2A7BE60088E4F0 /* DemoVC9Cell.m in Sources */ = {isa = PBXBuildFile; fileRef = E6FEDD771C2A7BE60088E4F0 /* DemoVC9Cell.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -129,6 +131,10 @@ 99E728A41BE5E22D00771161 /* SDRefreshView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDRefreshView.m; sourceTree = ""; }; 99E728A51BE5E22D00771161 /* UIView+SDExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+SDExtension.h"; sourceTree = ""; }; 99E728A61BE5E22D00771161 /* UIView+SDExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+SDExtension.m"; sourceTree = ""; }; + E6FEDD741C2A7BE60088E4F0 /* DemoVC9.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoVC9.h; sourceTree = ""; }; + E6FEDD751C2A7BE60088E4F0 /* DemoVC9.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoVC9.m; sourceTree = ""; }; + E6FEDD761C2A7BE60088E4F0 /* DemoVC9Cell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoVC9Cell.h; sourceTree = ""; }; + E6FEDD771C2A7BE60088E4F0 /* DemoVC9Cell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoVC9Cell.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -248,6 +254,7 @@ 487D3EDE1BCBA52900A66173 /* DemoVC */ = { isa = PBXGroup; children = ( + E6FEDD731C2A7BE60088E4F0 /* DemoVC9 */, 4867A48C1C292EB500BE8767 /* DemoVC8 */, 484511661C24395F0071BE2C /* DemoVC7 */, 486A382A1C0D8499000D43E5 /* DemoVC6 */, @@ -336,6 +343,17 @@ path = SDRefeshView; sourceTree = ""; }; + E6FEDD731C2A7BE60088E4F0 /* DemoVC9 */ = { + isa = PBXGroup; + children = ( + E6FEDD741C2A7BE60088E4F0 /* DemoVC9.h */, + E6FEDD751C2A7BE60088E4F0 /* DemoVC9.m */, + E6FEDD761C2A7BE60088E4F0 /* DemoVC9Cell.h */, + E6FEDD771C2A7BE60088E4F0 /* DemoVC9Cell.m */, + ); + path = DemoVC9; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -453,6 +471,8 @@ 48DA2B011BFB529200A771E6 /* UIView+SDAutoLayout.m in Sources */, 487D3EF41BCBB71500A66173 /* DemoVC3.m in Sources */, 486A382D1C0D852C000D43E5 /* DemoVC6.m in Sources */, + E6FEDD791C2A7BE60088E4F0 /* DemoVC9Cell.m in Sources */, + E6FEDD781C2A7BE60088E4F0 /* DemoVC9.m in Sources */, 48DBCD0E1C01DA1E002EC476 /* DemoVC5Model.m in Sources */, 484511711C2439830071BE2C /* DemoVC7Cell2.m in Sources */, 484511721C2439830071BE2C /* DemoVC7Model.m in Sources */, diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/xcuserdata/Chai.xcuserdatad/xcschemes/SDAutoLayout \346\265\213\350\257\225 Demo.xcscheme" "b/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/xcuserdata/Chai.xcuserdatad/xcschemes/SDAutoLayout \346\265\213\350\257\225 Demo.xcscheme" new file mode 100644 index 0000000..8c1ebf4 --- /dev/null +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/xcuserdata/Chai.xcuserdatad/xcschemes/SDAutoLayout \346\265\213\350\257\225 Demo.xcscheme" @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/xcuserdata/Chai.xcuserdatad/xcschemes/xcschememanagement.plist" "b/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/xcuserdata/Chai.xcuserdatad/xcschemes/xcschememanagement.plist" new file mode 100644 index 0000000..85e0a4c --- /dev/null +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo.xcodeproj/xcuserdata/Chai.xcuserdatad/xcschemes/xcschememanagement.plist" @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + SDAutoLayout 测试 Demo.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 487D3EB01BCB9EC700A66173 + + primary + + + 487D3EC91BCB9EC700A66173 + + primary + + + + + diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo/Base.lproj/Main.storyboard" "b/SDAutoLayout \346\265\213\350\257\225 Demo/Base.lproj/Main.storyboard" index 418c62c..3b326f1 100644 --- "a/SDAutoLayout \346\265\213\350\257\225 Demo/Base.lproj/Main.storyboard" +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo/Base.lproj/Main.storyboard" @@ -1,7 +1,8 @@ - + - + + @@ -41,5 +42,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo/DemoTableViewControler.m" "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoTableViewControler.m" index 52c5d7d..a5a60b4 100644 --- "a/SDAutoLayout \346\265\213\350\257\225 Demo/DemoTableViewControler.m" +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoTableViewControler.m" @@ -24,6 +24,7 @@ #import "DemoTableViewControler.h" #import "DemoVC5.h" +#import "DemoVC9.h" @implementation DemoTableViewControler @@ -33,16 +34,16 @@ - (void)viewDidLoad self.view.backgroundColor = [UIColor whiteColor]; - UIViewController *vc = [DemoVC5 new]; - vc.title = @"DemoVC5"; - [self.navigationController pushViewController:vc animated:YES]; +// UIViewController *vc = [DemoVC5 new]; +// vc.title = @"DemoVC5"; +// [self.navigationController pushViewController:vc animated:YES]; } #pragma mark - tableview datasourece and delegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 9; + return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -59,6 +60,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *demoClassString = [NSString stringWithFormat:@"DemoVC%ld", indexPath.row]; + + if (indexPath.row == 9) { + static UIStoryboard * s_storyboardHome = nil; + + if ( !s_storyboardHome ){ + s_storyboardHome = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; + } + DemoVC9 *vc9 = [s_storyboardHome instantiateViewControllerWithIdentifier:@"DemoVC9"]; + vc9.title = demoClassString; + [self.navigationController pushViewController:vc9 animated:YES]; + return; + } + + UIViewController *vc = [NSClassFromString(demoClassString) new]; vc.title = demoClassString; [self.navigationController pushViewController:vc animated:YES]; diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9.h" "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9.h" new file mode 100644 index 0000000..236093d --- /dev/null +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9.h" @@ -0,0 +1,13 @@ +// +// DemoVC9.h +// SDAutoLayout 测试 Demo +// +// Created by Chai on 15/12/23. +// Copyright © 2015年 gsd. All rights reserved. +// + +#import + +@interface DemoVC9 : UITableViewController + +@end diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9.m" "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9.m" new file mode 100644 index 0000000..f5a6941 --- /dev/null +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9.m" @@ -0,0 +1,123 @@ +// +// DemoVC9.m +// SDAutoLayout 测试 Demo +// +// Created by Chai on 15/12/23. +// Copyright © 2015年 gsd. All rights reserved. +// + +#import "SDRefresh.h" +#import "DemoVC9.h" +#import "DemoVC9Cell.h" +#import "DemoVC7Model.h" +#import "UITableView+SDAutoTableViewCellHeight.h" + +@interface DemoVC9 () +@property (nonatomic, strong) NSMutableArray *modelsArray; +@end + +@implementation DemoVC9 +{ + SDRefreshFooterView *_refreshFooter; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.tableView.estimatedRowHeight = 100; + + [self creatModelsWithCount:20]; + + __weak typeof(self) weakSelf = self; + + // 上拉加载 + _refreshFooter = [SDRefreshFooterView refreshView]; + [_refreshFooter addToScrollView:self.tableView]; + __weak typeof(_refreshFooter) weakRefreshFooter = _refreshFooter; + _refreshFooter.beginRefreshingOperation = ^() { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [weakSelf creatModelsWithCount:10]; + [weakSelf.tableView reloadData]; + [weakRefreshFooter endRefreshing]; + }); + }; + +} + +- (void)creatModelsWithCount:(NSInteger)count +{ + if (!_modelsArray) { + _modelsArray = [NSMutableArray new]; + } + + NSArray *iconImageNamesArray = @[@"icon0.jpg", + @"icon1.jpg", + @"icon2.jpg", + @"icon3.jpg", + @"icon4.jpg", + ]; + + + NSArray *textArray = @[@"当你的 app 没有提供 3x 的LaunchImage 时。然后等比例拉伸", + @"然后等比例拉伸到大屏。屏幕宽度返回 320否则在大屏上会显得字大", + @"长期处于这种模式下,否则在大屏上会显得字大,内容少这种情况下对界面不会", + @"但是建议不要长期处于这种模式下,否则在大屏上会显得字大,内容少,容易遭到用户投诉。", + @"屏幕宽度返回 320;然后等比例拉伸到大屏。这种情况下对界面不会产生任小。屏幕宽度返回 320;然后等比例拉伸到大屏。这种情况下对界面不会产生任小。屏幕宽度返回 320;然后等比例拉伸到大屏。这种情况下对界面不会产生任小。屏幕宽度返回 320;然后等比例拉伸到大屏。这种情况下对界面不会产生任小。" + ]; + + for (int i = 0; i < count; i++) { + int iconRandomIndex = arc4random_uniform(5); + int nameRandomIndex = arc4random_uniform(5); + + DemoVC7Model *model = [DemoVC7Model new]; + model.title = textArray[nameRandomIndex]; + + + // 模拟“有或者无图片” + int random = arc4random_uniform(100); + if (random <= 30) { + NSMutableArray *temp = [NSMutableArray new]; + + for (int i = 0; i < 3; i++) { + int randomIndex = arc4random_uniform(5); + NSString *text = iconImageNamesArray[randomIndex]; + [temp addObject:text]; + } + + model.imagePathsArray = [temp copy]; + } else { + model.imagePathsArray = @[iconImageNamesArray[iconRandomIndex]]; + } + + [self.modelsArray addObject:model]; + } +} + +#pragma mark - Table view data source +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.modelsArray.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + static NSString *ID = @"DemoVC9Cell"; + + DemoVC9Cell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; + if (cell == nil) { + cell = [self.tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath]; + } + cell.model = _modelsArray[indexPath.row]; + return cell; +} + + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + // >>>>>>>>>>>>>>>>>>>>> * cell自适应设置 * >>>>>>>>>>>>>>>>>>>>>>>> + // 只需一行代码即可实现单cell以及多cell的tableview高度自适应 + CGFloat height = [self cellHeightForIndexPath:indexPath cellContentViewWidth:[UIScreen mainScreen].bounds.size.width]; + NSLog(@"heightheight _%.2f",height); + return height; +} +@end diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9Cell.h" "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9Cell.h" new file mode 100644 index 0000000..f828928 --- /dev/null +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9Cell.h" @@ -0,0 +1,16 @@ +// +// DemoVC9Cell.h +// SDAutoLayout 测试 Demo +// +// Created by Chai on 15/12/23. +// Copyright © 2015年 gsd. All rights reserved. +// + +#import +@class DemoVC7Model; + +@interface DemoVC9Cell : UITableViewCell + +@property (nonatomic, strong) DemoVC7Model *model; + +@end diff --git "a/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9Cell.m" "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9Cell.m" new file mode 100644 index 0000000..f5abb4f --- /dev/null +++ "b/SDAutoLayout \346\265\213\350\257\225 Demo/DemoVC9/DemoVC9Cell.m" @@ -0,0 +1,34 @@ +// +// DemoVC9Cell.m +// SDAutoLayout 测试 Demo +// +// Created by Chai on 15/12/23. +// Copyright © 2015年 gsd. All rights reserved. +// + +#import "DemoVC9Cell.h" +#import "DemoVC7Model.h" +#import "UIView+SDAutoLayout.h" + +@interface DemoVC9Cell() +@property (weak, nonatomic) IBOutlet UIImageView *img; +@property (weak, nonatomic) IBOutlet UILabel *lbTitle; +@property (weak, nonatomic) IBOutlet UILabel *lbInfo; +@end + +@implementation DemoVC9Cell + +- (void)awakeFromNib { + self.selectionStyle = UITableViewCellSelectionStyleNone; + [self setupAutoHeightWithBottomView:_lbInfo bottomMargin:10]; +} + +- (void)setModel:(DemoVC7Model *)model +{ + _model = model; + + _lbTitle.text = model.title; + _lbInfo.text = model.title; + _img.image = [UIImage imageNamed:model.imagePathsArray.firstObject]; +} +@end