---
title: "类似sina微博cell右下角的图片效果"
author: "hua397"
date: "2011-10-09T14:05:08Z"
tags: []
categories: ["移动开发"]
slug: "sina-cell"
draft: false
lastmod: "2013-04-13T10:57:54Z"
id: 1187658
url: "https://hua397.iteye.com/blog/1187658"
---

昨天看了sina微博,看到cell右下角的图片,就想到思路应该是clip+rotate,今天随手测试,确实如此,果断上code:

```
UIView *containView=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 80)];
containView.backgroundColor=[UIColorredColor];
containView.layer.cornerRadius=10;
containView.clipsToBounds=YES;
[window addSubview:containView];

UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake((200-80), (80-40), 100, 60);
[btn setBackgroundImage:[UIImageimageNamed:@"touxiang.jpg"] forState:UIControlStateNormal];
[btn addTarget:selfaction:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
btn.layer.transform=CATransform3DMakeRotation(30.0*M_PI/180.0, 0, 0, 1);
[containView addSubview:btn];
```

 

还是很简单的,就两个地方:

 

1.containView.clipsToBounds=YES;当subviews的size超出superview的范围时,就把超出的那部分剪切掉;另外,在NO的情况下,超出的那部分是不能响应touchUpInside,不知为何...

 

2.btn.layer.transform=CATransform3DMakeRotation(30.0\*M\_PI/180.0, 0, 0, 1);这个简单地在Z上变换一下而已,细节参考文档

 

效果如下:

![](http://dl.iteye.com/upload/attachment/566003/ced2740a-d2e8-370e-a6da-b1442ab88a2e.png)