任何人都可以幫助我,我想要以相同的高度和寬度水平多次添加相同的圖像。重要的是我正在動態創建圖像視圖,我想爲所有圖像使用相同的圖像視圖!這是圖像我想像這樣水平製作
,但只有一行需要這樣。如何在ios中動態創建水平重複圖像
回答
這與婁方法使用stretchableImageWithLeftCapWidth
像這樣: -
UIImage *backgroundImage = [[UIImage imageNamed:@"SheetBackground.png"] stretchableImageWithLeftCapWidth:0.5 topCapHeight:0];
作爲您需要的示例: -
UIImage *backgroundImage = [[UIImage imageNamed:@"q4Ses.png"] stretchableImageWithLeftCapWidth:0.5 topCapHeight:0];
[_scro setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];
並使用您的圖片
它的輸出,如: -
[在這裏輸入的形象描述] [4]
你可以設置圖片爲上述方式的任意UISCrollview
,UIView
,按鈕比肩!你不需要forloop
。
更新: -
這上面整個後臺代碼,如果你只想添加一個lineof行,那麼你必須創建一個的UIView與參數需要海特並添加設置它的colorWithPatternImage
,並添加像貝婁
UIImage *backgroundImage = [[UIImage imageNamed:@"q4Ses.png"]
stretchableImageWithLeftCapWidth:1 topCapHeight:0];
UIView *v=[[UIView alloc]
initWithFrame:CGRectMake(0, 0, _scro.frame.size.width, 45)];
[v setBackgroundColor:[UIColor
colorWithPatternImage:backgroundImage]];
[_scro addSubview:v];
而且它的輸出是: -
查看圖像的高度。但是這個觀點可以有任何寬度。
然後用下面的代碼在這個視圖中設置你的瓷磚圖像。
UIImage *tiledImage = [UIImage imageNamed:@"myTiledImage.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:tiledImage];
這會讓你的圖像水平平鋪多次。
如果視圖到處散佈於屏幕上的圖像,那麼你就必須將以下代碼添加到您的視圖
self.view.clipToBounds = YES;
你是否確定這一點?...它不是橫向......在公園附近...... –
你是什麼意思「四周公園」?我沒有讓你... – CodenameLambda1
倪身份證上想申請背景完全只需要寬度30,身高40 –
UIScrollView *myScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
CGFloat scrollWidth = 0.f;
for (int i=0;i<10;i++)//i=10,put as many image number u want to display
{
imageView = [[UIImageView alloc] initWithFrame:
CGRectMake(scrollWidth, 0, 80, 60.f)];
imageView.image=[UIImage imageNamed:@"urimagename"];
imageView.tag=i;
[myScrollView addSubview:imageView];
scrollWidth += 100;
}
myScrollView.contentSize = CGSizeMake(scrollWidth, 100);
編輯:
您可以另一種方式實現這一目標。
CodenameLambda1的答案比上面的答案要好。但是仍然需要在@CodenameLambda1的答案中完成一些更改。由於SOP的要求是將其顯示在scrollview中,因此而不是self.view使用scrollview。
UIScrollView *vie=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
UIImage *tiledImage = [UIImage imageNamed:@"login"];
vie.backgroundColor = [UIColor colorWithPatternImage:tiledImage];
vie.contentSize=CGSizeMake(1400,60);
vie.clipsToBounds = YES;
[self.view addSubview:vie];
- 1. 如何重複圖像,但僅水平?
- 2. 如何創建水平圖像庫
- 3. 如何創建水平連續圖像?
- 4. 動態創建圖像水印
- 5. 在iOS上重複水平線並重復垂直線的圖像
- 6. iOS圖像庫水平滾動
- 7. 如何在水平滾動視圖中創建延遲加載
- 8. ios中的動態水平滾動條
- 9. 創建靜態水平滾動
- 10. 創建動態水平菜單
- 11. 如何動態創建NativeScript中的水平按鈕列表?
- 12. 如何使用jQuery創建動態水平滾動?
- 13. 如何在iOS中創建圖像庫
- 14. 如何水平創建三個圖像視圖
- 15. 如何在ios中使用MIM圖表庫創建水平條形圖?
- 16. 如何創建水平div移動
- 17. 如何創建水平滾動列表?
- 18. 水平滾動視圖iOS
- 19. 創建iOS中水平虛線
- 20. 動態創建水平和垂直滾動視圖Android
- 21. 如何從平鋪圖像動態創建AnimationDrawable
- 22. 如何使背景圖像水平重複?
- 23. 如何重複LinearLayout的水平和垂直圖像背景?
- 24. 如何垂直和水平重複圖像?
- 25. 如何在iPhone上創建水平滾動視圖?
- 26. 如何在動態創建的水平和垂直佈局中滾動?
- 27. 在頁腳中水平重複x圖像
- 28. 在java中垂直和水平重複圖像
- 29. iPhone在AppStore中水平滾動圖像
- 30. 如何動態創建圖像Graphics.DrawImageUnscaledAndClipped
是你用scrollview嗎? –
雅滾動使用 –
你想實現什麼?問題不清楚... – preetam