??????,廢不多說,直接上效果圖
未命名.gif
然后廢話不多說,直接丟代碼(才不說是因為沒啥亮點,才不裝x的呢??)。
//
// ViewController.m
// StretchTableView
//
// Created by wuwj on 16/9/2.
// Copyright ? 2016年 wuwj. All rights reserved.
//
#import "ViewController.h"
#import "fiveTableViewCell.h"
#import "UILabel+StringFrame.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) UITableView *tableView;
@end
@implementation ViewController{
CGFloat height;
NSString *detailStr;
}
static NSString *fiveCell = @"fivecell";
- (void)viewDidLoad {
[super viewDidLoad];
detailStr = [self titleArray][0];
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:(UITableViewStylePlain)];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
_tableView = tableView;
[_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([fiveTableViewCell class]) bundle:nil] forCellReuseIdentifier:fiveCell];
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return height + 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
fiveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:fiveCell];
UILabel *detailLabel = [cell.contentView viewWithTag:11];
UIButton *button = [cell.contentView viewWithTag:12];
detailLabel.text = detailStr;
detailLabel.numberOfLines = 0;
height = [detailLabel boundingRectWithSize:(CGSizeMake(_tableView.frame.size.width, 1000))].height;
[button addTarget:self action:@selector(moreMessage) forControlEvents:(UIControlEventTouchUpInside)];
return cell;
}
- (void)moreMessage{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
fiveTableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:fiveCell forIndexPath:indexPath];
UIButton *button = [cell.contentView viewWithTag:12];
if ([button.titleLabel.text isEqualToString:@"收起"]) {
detailStr = [self titleArray][0];
[button setTitle:@"展開全文" forState:(UIControlStateNormal)];
}else{
detailStr = [self titleArray][1];
[button setTitle:@"收起" forState:(UIControlStateNormal)];
}
[_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:(UITableViewRowAnimationNone)];
}
- (NSArray *)titleArray{
return @[@"9月7日(北京時間9月8日凌晨),蘋果將在舊金山舉行新品發(fā)布會,正式發(fā)布新一代iPhone。隨著發(fā)布日期的臨近,新一代iPhone已經(jīng)曝光的差不多了,不過命名卻讓人有點摸不到頭腦。迄今為止,已經(jīng)有了iPhone 7、iPhone 6 SE以及iPhone 7 SE等多種命名方式。",
@"9月7日(北京時間9月8日凌晨),蘋果將在舊金山舉行新品發(fā)布會,正式發(fā)布新一代iPhone。隨著發(fā)布日期的臨近,新一代iPhone已經(jīng)曝光的差不多了,不過命名卻讓人有點摸不到頭腦。迄今為止,已經(jīng)有了iPhone 7、iPhone 6 SE以及iPhone 7 SE等多種命名方式。但,最新曝光的包裝盒顯示,新一代iPhone的命名就叫iPhone 7,不會搞出什么幺蛾子了。從外媒曝光的包裝盒來看,iPhone 7 Plus會有32GB版可選,而且包裝盒內附贈一款名為AirPods的無線耳機。此外,此前曝光的消息顯示,包裝盒內可能還會有一個Lightning接口到3.5mm耳機接口轉換器。是不是真的?下周見分曉。"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
跑路(裝完就跑,真爽????)。
https://pan.baidu.com/s/1nuWuPrb百度網(wǎng)盤下載demo