I have two UISliders in the same view.My requirement is,when user change the value of 1st slider,the 2nd slider value should be change according to it.So,in 2nd slider I want to invisible its thumb.Although I have clear the color of its thumb,It is visible to the user.How can I solve it ?
Easy One :
[_slider setThumbImage:[UIImage new] forState:UIControlStateNormal];
Simply set the image for the thumb to be nil
UIImage *empty = [UIImage new];
[theSlider setMinimumTrackImage:[UIImage alloc] forState:UIControlStateNormal];
[theSlider setMaximumTrackImage:[UIImage alloc] forState:UIControlStateNormal];
Simply go to xib select slider --> Utilities --> show attributes Inspectors --> Thumb Tint Colour (Clear Thumb tint colour)
Related
I would like to create something like this:
I would like to place an UITextField with an UIButton into one grey frame, and I would like the button's border to be contained by this grey frame.
Please somebody show me some sample code for this!
Thx!
1. Use a UIImageView of required rect. Set the background image to the gradient gray colour image.
UIImageView*myImageView=[[UIImageView alloc] initWithFrame:yourFrame];
[myImageView setImage:[UIImage imageNamed:#"grayBackground.png"];
[self.view addSubview:myImageView];
2. Use a round rect. UITextField make it a subview of the image view. Use a place holder as "Write a reply..." make it a subview to your imageview.
UITextField*myField=[[UITextField alloc] initWithFrame:yourRect];
[myField setBorderStyle:UITextBorderStyleRoundedRect];
[myField setPlaceholder:#"Write a reply..."];
[myImageView addSubview:myField];
3. Use a UIButton with type Custom and the send image as its background image, make it a subview to your imageview.
UIButton*myButton=[UIButton buttonWithType:UIButtonTypeCustom];
[myButton setFrame:yourRect]
[myButton setBackgroundImage:[UIImage imageNamed:#"sendImage.png"] forState:UIControlStateNormal];
[myImageView addSubView:myButton];
Simple way is to create title bar with grey background and delete the title.and place textfield and button which u want to place it.configure the size and button outside the title bar and drag it to the title bar..u'll get like the image which u have got.
I use [button setImage:image forState:0]; to set a image to a UIButton.
Then I want the title of it using [button setTitle:[titleArray objectAtIndex:i] forState:0];.
But the image cover the title which I want to show in front of the image.
Any solution?
Thanks!
use setBackgroundImage:forState instead. When you use the (foreground) image, you dont get to set a title.
i hav a more buttons on my scrool view so if one of them clickrd i just want to highlight the button untill the any of the button clicked again....
so i just want to show the button in clicked mode......
thanks in advance.....
Set the button's highlighted property to YES:
myButton.highlighted = YES;
Use these two lines:
[myButton setBackgroundImage: [UIImage imageNamed:#"myImage.png"]];
myButton.highlighted = YES;
Dont use:
[myButton setImage: [UIImage imageNamed:#"myImage.png"]];
This will hide the highlighting of button.
I want to overlay an image over a button. the button has a background image. If i want to overlay a semi transparent image over the button, suppose i overlay a red color image, which is semi transparent. Can any one suggest how to do that? Suggest some documentation.
UIImageView *overlay = [[UIImageView alloc] initWithImage:...];
[overlay setAlpha:0.5];
UIButton *button = [[UIButton alloc] initWithType:UIButtonTypeRoundedRect];
[button setBackgroundImage:...];
[button addSubview:overlay];
[overlay release];
UIButton also has an image property as well as a backgroundImage property, although I'm unsure how transparency would work with it.
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html
Following dc answer, note that changing the button alpha will affect also the overlay transparency, so check that button alpha is 1.0f (default value).
Note also that you should release the overlay variable after adding it as subview to button, otherwise, you'll get a memory leak.
I understand how you can have a minimum track and maximum track image, and how it can be stretchable. However, for my needs, that might not be enough control.
I have a situation where on the left hand side (minimum track) I need to display two different colors, based on data. The left hand side actually represents two pieces of data, but yet there still exists only a single thumb between minimum and maximum.
so how can i do this???
Any sample code??
i actually want like this
photo link
On left hand side it is of grinish color but when it exceeds the thumb image it becomes red..
In your .h file
IBOutlet UISlider *slide;
in your .m file
UIImage *minImage = [UIImage imageNamed:#"unselected.png"];
UIImage *maxImage = [UIImage imageNamed:#"selected.png"];
UIImage *tumbImage= [UIImage imageNamed:#"thumb.png"];
minImage=[minImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
maxImage=[maxImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[slide setMinimumTrackImage:minImage forState:UIControlStateNormal];
unselected.png and selected.png are the images that act as bar and thumb.png which slide over the bar.
Put your image swapping code in your slider value-reading method, which is usually:
-(IBAction)sliderChanged:(id)sender; {}
Swap your custom green image with a custom red image whenever your slider value reaches some predefined value. See example below.
// Switches the -thumbImage between an ivar named highImage and lowImage
// when the slider passes the halfway point
if (sliderValue > 0.5) {
[self updateSliderThumbWithImage:self.highImage];
} else {
[self updateSliderThumbWithImage:self.lowImage];
}
define the slider image update method like this:
-(void)updateSliderThumbWithImage:(UIImage *)image;
{
[self.slider setThumbImage:image forState:UIControlStateNormal];
[self.slider setThumbImage:image forState:UIControlStateHighlighted];
}
// You have to set thumb images for both states
// or your image will vanish when user slides it.
// Not sure if you have to do the same with the track image, though.
Hope this helps somebody.
I'm not sure if I can visualize what you need (any chance you can post a sketch?), but do a search for UISlider and you can find some pretty creative uses. Otherwise you can create your own custom UIControl.
(source: texlege.com)