IPhone开发中tableview cell的气泡样式的实现


http://deeryrl.blog.163.com/blog/static/1525428742011112112120767/

上次在做自己的AtoG项目的时候,总是发现tableview中的cell太丑陋,于是就想办法来将它做成类似iphone中的imessage中对话的形式,找了一些代码,不是很难,下面分享给大家,其中,有些是自己的代码,有些是从网络上其他地方获取的。下面的就是实现的效果,当然了, 你还需要一个类似气泡的图片,我用的就是一个特别小的44 x 31像素的绿色png图片:

IPhone开发中tableview cell的气泡样式的实现 - 阿迪易 - 又见阿迪易

代码如下:

    UIImage *bubble = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bubble" ofType:@"png"]];

    

    UIImageView *bubbleImageView = [[UIImageView alloc] initWithImage:[bubble stretchableImageWithLeftCapWidth:21 topCapHeight:14]];

    

    UIFont *font = [UIFont systemFontOfSize:13];

    

    //The following code to control the size of text string.

    CGSize size = [post.content sizeWithFont:font constrainedToSize:CGSizeMake(230.0f, 1000.0f) lineBreakMode:UILineBreakModeCharacterWrap];

    

    UILabel *bubbleText = [[UILabel alloc] initWithFrame:CGRectMake(40, 45, size.width+10, size.height+10)];

    bubbleText.backgroundColor = [UIColor clearColor];

    bubbleText.font = font;

    bubbleText.numberOfLines = 0;

    bubbleText.lineBreakMode = UILineBreakModeCharacterWrap;

    bubbleText.text = post.content;

    

    //The following code to control the size of bubble image.

    bubbleImageView.frame = CGRectMake(30,5, 260.0f, size.height+95.0f);

    

    //The following code is to set uiview size.

    returnView.frame = CGRectMake(30, 5, 260.0f, size.height+95.0f);

    

    [returnView addSubview:bubbleImageView];

    [bubbleImageView release];

    [returnView addSubview:bubbleText];

    [bubbleText release];


如果大家有什么不懂的,可以留下问题,我们一起探讨。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值