2013-01-17 112 views
1

什么是创建一个自定义的UIView的最佳方式?所以我得到了3张图片(上,中,BOT) 和我想的图像按钮内唯一)创建自定义的UIView绘制

enter image description here enter image description here enter image description here

我怎么能创造这(它必须是可调整大小(以高度与UIView的,所以我可以把图像里面,而且调整的意见(我想这在UITablecell)

回答

0

尝试这两个环节进行自定义的UITableView绘图:

cocoawithlove.com/2009/04/easy -custom-uitablev IEW-drawing.html

http://adeem.me/blog/2009/05/30/iphone-sdk-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/

在那里,你应该能够单独设置每个单元格”的高度。如果不存在,则覆盖的UITableViewDelegate方法

tableView:heightForRowAtIndexPath: 

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html

0

如果你使用的是iOS 5看看在UIImageresizableImageWithCapInsets:方法。

这允许您指定图像的一部分,应该调整,哪些应该自动缩放。这对于重复使用背景图像非常理想,就像您的情况一样。

所以,你会用蓝色背景创建可调整大小的图像,并从应与图像调整边缘指定偏移。您不必切片或切分图像,只需将其作为一个整体图像提供即可,缩放将自动进行,并且如果正确指定了帽子插图,圆角将保持完整。

// Change the edge insets to match your image... 
UIImage *backgroundImage = [[UIImage imageNamed:@"button_background"] 
    resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]; 

// Create an image view to hold the new image 
UIImageView *myBackgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage]; 

// [...] here make sure to size your image view to match the size of your parent view 

// Add the background image view to the view 
[self addSubview:myBackgroundImageView]; 

然后,您可以自由使用类似的技术来定制tableview单元格。但这里的想法是使用带有边缘插图的可调整大小的图像来动态缩放背景图像。

Here是一个很好的博客文章,解释边插图。

希望有所帮助。