我在使用兩張圖像自定義UIProgressView
時遇到困難。我在互聯網上發現了很多有用的問題,但我的問題有點不同。也許在某種程度上,我正在使用的圖像是四捨五入的沒有角色的矩形;因此,stretchableImageWithLeftCapWidth
方法似乎沒有幫助我的情況。當我拉伸圖像時,由於圖像的圓角有一些空間,因此有一個問題發佈在此link具有圓角圖像的自定義UIProgressView
2
A
回答
2
您將不得不執行自定義UiProgressView
並使用以下代碼進行視圖並添加圖像填充和後臺進度視圖,在我的情況下,他們是loaderBar.png爲填充和timeLineBig.png爲背景。
CustomProgressView.h
#import <UIKit/UIKit.h>
@interface CustomProgressView : UIProgressView
@end
CustomProgressView.m
#define fillOffsetX 2
#define fillOffsetTopY 2
#define fillOffsetBottomY 2
#import "CustomProgressView.h"
@implementation CustomProgressView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
CGSize backgroundStretchPoints = {10, 10}, fillStretchPoints = {7, 7};
// Initialize the stretchable images.
UIImage *background = [[UIImage imageNamed:@"timelineBig.png"] stretchableImageWithLeftCapWidth:backgroundStretchPoints.width
topCapHeight:backgroundStretchPoints.height];
UIImage *fill = [[UIImage imageNamed:@"loaderBar.png"] stretchableImageWithLeftCapWidth:fillStretchPoints.width
topCapHeight:fillStretchPoints.height];
// Draw the background in the current rect
[background drawInRect:rect];
// Compute the max width in pixels for the fill. Max width being how
// wide the fill should be at 100% progress.
NSInteger maxWidth = rect.size.width - (2 * fillOffsetX);
// Compute the width for the current progress value, 0.0 - 1.0 corresponding
// to 0% and 100% respectively.
NSInteger curWidth = floor([self progress] * maxWidth);
// Create the rectangle for our fill image accounting for the position offsets,
// 1 in the X direction and 1, 3 on the top and bottom for the Y.
CGRect fillRect = CGRectMake(rect.origin.x + fillOffsetX,
rect.origin.y + fillOffsetTopY,
curWidth,
rect.size.height - fillOffsetBottomY);
// Draw the fill
[fill drawInRect:fillRect];
}
@end
最後當你想使用的自定義進度視圖然後調用這樣的事情...
self.customProgressView=[[CustomProgressView alloc] initWithFrame:CGRectMake(xValue, yValue, widthofProgressView, heightofProgressView)];
確保您根據您的要求
1
如果您有streching圖像使用問題爲x值,y值,widthofProgressView & heightofProgressView設置自定義的值調整resizableImageWithCapInsets:
UIImage *image = [baseImage resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5) resizingMode:UIImageResizingModeStretch];
相關問題
- 1. 自定義UIProgressView與圖像
- 2. 使用自定義圖像的圓角
- 3. Android:具有自定義視圖和圓角的AlertDialog
- 4. 帶有自定義圖像的Mac圓角紋理按鈕
- 5. Android的圓形圖像與自定義的角落
- 6. UIProgressView具有圓角進度軌跡邊緣 - Swift 3
- 7. android自定義searchView圓角
- 8. 自定義UIButton圓角
- 9. 使用自定義小部件的圓形圖像角落
- 10. iphone中的自定義UIProgressView
- 11. ProgressDialog具有自定義圖像
- 12. 創建具有自定義圖像幀
- 13. 自定義UIProgressView繪圖怪異
- 14. 圓角圖像
- 15. 帶有圓角的Android自定義組件視圖
- 16. 圖像的圓角
- 17. UIProgressView自定義最大值
- 18. UiProgressView自定義與PaintCode
- 19. 自定義的線性佈局,圓角
- 20. dojox.drawing.Drawing - 用圓角創建矩形的自定義工具
- 21. Javascript圓角圖像
- 22. 帶有圓角的ListView中的圖像
- 23. CSS:如何添加具有邊框和無圖像的圓角?
- 24. 具有圓角和圖像資源背景的Linearlayout?
- 25. 帶圖像的自定義工具欄
- 26. XAML:FlowDocument中所有圖像的圓角!
- 27. 設置自定義圓角scrollbarThrtVertical scrollbarTrackVertical android
- 28. 自定義NSView與圓角和陰影
- 29. 目標C,圓角自定義窗口?
- 30. 具有圓角和透明背景的自定義警報對話框
感謝您的回答,我會試一試並回復給您,如果我遇到問題 – sam46 2013-02-08 15:05:20
似乎很有幫助,但仍然需要在圖像上對高度和寬度進行修復,但我認爲,因此,正如你在答覆中所說的,感謝100萬 – sam46 2013-02-08 15:15:24
做到了! – sam46 2013-02-08 16:23:37