国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

iOS開發(fā)中tableViewCell的懸浮效果

2019-11-14 18:38:33
字體:
供稿:網(wǎng)友

其實很早就想寫博客了,只是感覺自己的技術(shù)不行,寫出來的東西技術(shù)性不強,寫出來也沒什么用,不過后來想想,寫寫博客記錄開發(fā)中遇到的問題也不錯....

今天我想寫的是tableView的懸浮效果,因為我們公司最近在開發(fā)社區(qū),就是和百度貼吧類似的,嵌套在應(yīng)用中,而其中關(guān)于每一個的帖子要像這種效果

開始是做不出這種效果,就直接寫個tableView算了,后來跟問了下做安卓的那邊,原來是陰影的效果...

說到這里,相信好多同學(xué)都知道,好吧,我們開始上代碼,首先是創(chuàng)建tableView,這個就不用多說了吧,這是創(chuàng)建tableView的.m文件

#import "ViewController.h"#import "DemoCell.h"//屏幕寬度#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)//屏幕高度#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)@interface ViewController () <UITableViewDataSource,UITableViewDelegate>@PRoperty (nonatomic,strong)UITableView *tableView;@property (nonatomic,assign)CGFloat height;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    [self createTabelView];}- (void)createTabelView{    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT-20) style:UITableViewStylePlain];    self.tableView.delegate = self;    self.tableView.dataSource = self;    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;    [self.view addSubview:self.tableView];}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 5;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    //注意重用    static NSString *cellId = @"cell";    DemoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];    if(cell == nil){        cell = [[DemoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];    }    return cell;}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    return [DemoCell getHeight] + 10;}@end

然后是自定義cell,自定義cell要注意因為要寫出懸浮效果,所以我想的是給Cell加一層View,這個View的frame比Cell的contentView小一圈,在設(shè)置邊框的陰影,就能寫出懸浮效果了,這是自定義Cell的.m文件

#import "DemoCell.h"#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height) @interface DemoCell()@property (nonatomic,strong)UIView *bgView;@end@implementation DemoCell- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){        [self createUI];    }    return self;}//重點在這里- (void)createUI{    //創(chuàng)建一個UIView比self.contentView小一圈    self.bgView  = [[UIView alloc] initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH - 20, 100)];    self.bgView.backgroundColor = [UIColor whiteColor];    //給bgView邊框設(shè)置陰影    self.bgView.layer.shadowOffset = CGSizeMake(1,1);    self.bgView.layer.shadowOpacity = 0.3;    self.bgView.layer.shadowColor = [UIColor blackColor].CGColor;    [self.contentView addSubview:self.bgView];}+ (CGFloat)getHeight{    //在這里能計算高度,動態(tài)調(diào)整    return 100;}@end

運行起來的效果圖,是不是棒棒噠

 結(jié)束,第一篇博客就寫到這里了,就算沒人看(還是希望有人看的),我也會寫下去的哦...

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 辰溪县| 抚远县| 天津市| 石城县| 盐边县| 吴江市| 白河县| 石柱| 甘肃省| 耒阳市| 岗巴县| 潮安县| 平邑县| 塘沽区| 蚌埠市| 舟山市| 南木林县| 沅江市| 北川| 林西县| 竹溪县| 华宁县| 巴马| 江门市| 河源市| 双峰县| 平顶山市| 信丰县| 梨树县| 伊春市| 敖汉旗| 简阳市| 大邑县| 建德市| 交城县| 罗甸县| 兴和县| 随州市| 丹凤县| 灵台县| 昔阳县|