如何创建自定义进度视图?
在iphone中,UIProgressView高度是固定的,我需要创建高度40(可变高度)的UIProgressView,如何在drawRect方法中编写我的自定义代码?我是石英绘图新手,可以绘制任何可用的样品。
提前致谢。
In iphone the UIProgressView height is fixed, i need to create UIProgressView for height 40(variable height), how to write my custom code in drawRect method? i am new to Quartz drawing any samples available.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,您可能不需要子类化
drawRect:
。大概您的进度视图的图像是“可拉伸的”(即它们具有固定大小的左端和右端,中间部分可以拉伸)?您可以通过加载
UIImage
并调用stretchableImageWithLeftCapWidth:topCapHeight:
获取可以分配给UIImageView 的图像
。然后,当您调整UIImageView
的大小时,图像会自动正确重新绘制 - 左右“大写字母”绘制在图像视图的左右两端,中间部分被拉伸以填充中间。您的进度条将成为一个视图,其中包含两个
UIImageView
作为子项:一个用于背景,另一个用于填充进度条。通过巧妙地使用autoresizingMask
,您只需更改进度条填充的框架即可更新显示。Actually, you may not need to subclass
drawRect:
.Presumably the images for your progress view are "stretchable" (i.e. they have fixed size left and right ends with a middle part that can be stretched)? You can create a stretchable image by loading a
UIImage
, callingstretchableImageWithLeftCapWidth:topCapHeight:
to get an image you can assign to aUIImageView
. Then, when you resize theUIImageView
, the image redraws correctly automatically -- the left and right "caps" are drawn at the left and right end of the image view, and the middle part is stretched to fill the middle.Your progress bar becomes a view that holds two
UIImageView
s as children: one for the background and one for the filled progress bar. With clever use of theautoresizingMask
, you should only need to change the frame of the progress bar fill to update the display.