Vijay_07 Vijay_07 -4 years ago 95
iOS Question

How to repeat image horizantly in dynamic creation in ios

Could any one help me i want to add same image multiple times horizontally with same height and width. Important thing is i am creating image view dynamically i want to use same image view for all images! This is image enter image description here i want to make horizontally like this enter image description here but only one row needed like this.

Answer Source

this with Bellow Method using stretchableImageWithLeftCapWidth like this way:-

UIImage *backgroundImage = [[UIImage imageNamed:@"SheetBackground.png"] stretchableImageWithLeftCapWidth:0.5 topCapHeight:0];

as par your need example:-

UIImage *backgroundImage = [[UIImage imageNamed:@"q4Ses.png"] stretchableImageWithLeftCapWidth:0.5 topCapHeight:0];

  [_scro setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];

And using your image enter image description here

It's Output like:-

enter image description here

![enter image description here][4]

you can set this image as above way any of UISCrollview, UIView,button as par you need no need to forloop for that.

UPDATE:-

This above code for entire Background if you wish to add only for one lineof row then you have to create one UIview as par you need Hight and add set it's colorWithPatternImage and add like Bellow

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];

And it's Output is :-

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download