Here I used UISegmentationControl, I need to set the image for segmentation.In ios7, the images are placed in correct position but in ios6 and earlier versions the images are in incorrect sizes, please see the attached images
In IOS6 the images are in wrongly displayed images
In IOS7 the images are in correct way
Code I used to set the images as
UIImage *separator;
UIImage *onstate;
UIImage *offstate;
UIImage *unselected_right_state;
UIImage *unselected_left_state;
if ([UIImage instancesRespondToSelector:#selector(imageWithRenderingMode:)]) {
separator = [[UIImage imageNamed:#"gseprator.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
onstate = [[UIImage imageNamed:#"on.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
offstate = [[UIImage imageNamed:#"off.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
unselected_right_state = [[UIImage imageNamed:#"gon2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
unselected_left_state = [[UIImage imageNamed:#"goff1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
else {
separator = [UIImage imageNamed:#"gseprator.png"];
onstate = [UIImage imageNamed:#"on.png"];
offstate = [UIImage imageNamed:#"off.png"];
unselected_right_state = [UIImage imageNamed:#"gon2.png"];
unselected_left_state = [UIImage imageNamed:#"goff1.png"];
}
if (true) {
[[cell onoffSegment] setImage:onstate forSegmentAtIndex:0];
[[cell onoffSegment] setImage:unselected_right_state forSegmentAtIndex:1];
}else{
[[cell onoffSegment] setImage:unselected_left_state forSegmentAtIndex:0];
[[cell onoffSegment] setImage:offstate forSegmentAtIndex:1];
}
Related
I am adding imageview in viewcontroller.
It is working good in ios6 but in ios7 It display with white background.
I have tried clearColor but it's not working.
Here is my code
[imgcharacter setImage:[UIImage imageNamed:[NSString stringWithFormat:#"character%d.png",reelBtnTag]]];
[imgcharacter setFrame:CGRectMake(100,100, 247.5f, 385.0f)];
imgcharacter.userInteractionEnabled=YES;
[imgcharacter setBackground : [UIColor clearColor]];
[captureview addSubview:imgcharacter];
Try this way....
NSData *imageData = UIImagePNGRepresentation(Your Image);
UIImage *image=[UIImage imageWithData:imageData];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 52, 40, 50)];
imageView.backgroundColor = [UIColor clearColor];
imageView.image = image;
I have added a UIView, On that UIImageView using UIBuider,
Now I want to apply animation on that imageView, so I'v taken an array of images & adding that
array to imageView through this code
NSArray *animationArray=[[NSArray alloc]init];
animationArray=[NSArray arrayWithObjects:
[UIImage imageNamed:#"rabbit1.png"],
[UIImage imageNamed:#"rabbit2.png"],
[UIImage imageNamed:#"rabbit3.png"],
[UIImage imageNamed:#"rabbit4.png"],
[UIImage imageNamed:#"rabbit5.png"],
[UIImage imageNamed:#"rabbit6.png"],
[UIImage imageNamed:#"rabbit7.png"],
[UIImage imageNamed:#"rabbit8.png"],
[UIImage imageNamed:#"rabbit9.png"],
[UIImage imageNamed:#"rabbit10.png"],
[UIImage imageNamed:#"rabbit11.png"],
[UIImage imageNamed:#"rabbit12.png"],
[UIImage imageNamed:#"rabbit13.png"], nil];
tempImageView.animationImages=animationArray;
tempImageView.animationDuration=2;
tempImageView.animationRepeatCount=0;
[tempImageView startAnimating];
tempImageView is created using UIBuider
But it is not woking, isn't showing anything.
There seems to a bug in the story board auto layout..i found the same no result..
Try it via code this works..
mainImageView = [[UIImageView alloc]init];
NSArray *animationArray = [[NSArray alloc]init];
animationArray = [NSArray arrayWithObjects:[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"], nil]; //add your images here
[mainImageView setFrame:CGRectMake(50,50,100,100)];
mainImageView.animationImages = animationArray; //mainImageView is imageview
mainImageView.animationDuration = 2;
mainImageView.animationRepeatCount = 0;
[mainImageView startAnimating];
[self.view addSubview:mainImageView];
I have created a button using code shown below -
UIImage *kalenderImage = [UIImage imageNamed:#"start_icon_calendar_u.png"];
UIImageView *kalenderImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kalenderImage.size.width/2, kalenderImage.size.height/2)] autorelease];
[kalenderImageView setImage:kalenderImage];
UILabel* kalendarLabel = [[[UILabel alloc] initWithFrame:CGRectMake (0, kalenderImage.size.height/2-15, kalenderImage.size.width/2, kalenderImage.size.height/2)] autorelease];
kalendarLabel.text = #"Kalender";
[kalenderButton addSubview:kalenderImageView];
[kalenderButton addSubview:kalendarLabel];
[kalenderButton addTarget:self action:#selector(showCalendar:) forControlEvents:UIControlEventTouchUpInside];
I need to change the image of button for UIControlStateHighlighted state. How can i do this ?
I dont want to use
KalenderButton setBackgroundImage:#"" forState:]
[KalenderButton setImage:#"" forState]
Its very simple. Look at the following code. It checks the file is locked and changes the image of the button accordingly. You can edit the code according to your necessity.
if (fileLocked) {
UIImage *image = [UIImage imageNamed: [NSString stringWithFormat:#"icon-lock.png"]];
[lockButton setImage:image forState:UIControlStateNormal];
} else {
UIImage *image = [UIImage imageNamed: [NSString stringWithFormat:#"icon-unlock.png"]];
[lockButton setImage:image forState:UIControlStateNormal];
}
It works.
I have written a code for setting imageview ...as per the button clicked...but my problem is when i press the button it is giving me the error like...too many arguments to function ImageNamed...while executing this line...
UIImage* photo = [UIImage imageNamed:#"robort %d.jpg",x];
the whole code is....
-(void)buttonClicked:(UIButton*)button
{
NSLog(#"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
UIImage* photo = [UIImage imageNamed:#"robort %d.jpg",x];
NSLog(#"%d",x);
CGSize photoSize = [photo size];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)];
[imageView setImage:photo];
[self.view addSubview:imageView]; }
use UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:#"robort de nero%d.jpg",x]];
cheers :)
Try this
-(void)buttonClicked:(UIButton*)button
{
NSLog(#"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
NSString *imageName = [NSString stringWithFormat:#"robort %d.jpg",x];
UIImage* photo = [UIImage imageNamed:imageName];
NSLog(#"%d",x);
CGSize photoSize = [photo size];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)];
[imageView setImage:photo];
[self.view addSubview:imageView];
}
You need to use:
UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:#"robort %d.jpg",x]];
Use this
UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:#"robort %d.jpg",x]];
can we use a gif image as a background?
i want to set an gif image as a background, like some birds flying ....
can we use gif image to set as background.???
if yes than how?
thanks and regards
Yes you can - I assume you want an animated gif?
It's the same CSS rule as a static background.
body {
background: url(animated.gif);
}
Here, i got the solution.
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"default1.jpg"],
[UIImage imageNamed:#"default2.jpg"],
[UIImage imageNamed:#"default3.jpg"],
[UIImage imageNamed:#"default4.jpg"],
[UIImage imageNamed:#"default5.jpg"],
[UIImage imageNamed:#"default6.jpg"],
[UIImage imageNamed:#"default7.jpg"],
[UIImage imageNamed:#"default8.jpg"],
[UIImage imageNamed:#"default9.jpg"],
[UIImage imageNamed:#"default10.jpg"],
[UIImage imageNamed:#"default11.jpg"],
[UIImage imageNamed:#"default12.jpg"],
[UIImage imageNamed:#"default13.jpg"],
[UIImage imageNamed:#"default14.jpg"],
[UIImage imageNamed:#"default15.jpg"], nil];
animatedImageView.animationDuration = 3.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];