I created a subclass of UISlider called VolumeSlider, with the intent being to just increase the thickness of the track and reduce the size of the thumb (similar to the appearance of the default volume view in the music player). I don't want to use custom images, as the default iOS 7 slider has the basic appearance I want. In my subclass, I'm overriding the following 2 methods in order to achieve this:
- (CGRect)trackRectForBounds:(CGRect)bounds
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value
My question is: How can I apply this UISlider subclass to my MPVolumeView?
Related
The question might seem confusing so let me clarify.
I am working on a very heavily content driven app. Content is obtained asynchronously and there are often dozen or more elements on screen that represent content. Images, text...etc...all these are implemented via UIView subclasses.
I'd like to be able to set per app level (via appearance proxy or some other method), that once the view is ready for being rendered visible, it should fade in instead of just show up suddenly after the next render pass.
Anybody any ideas? Is there some CALayer property that would allow this easily?
Drawrect? Override hidden? A convenience public wrapper function using UIView animations internally?
Once again, I know how to do this on individual level using UIView animations methods. What I want is a global change of behaviour for all UIViews.
You can create a UIView subclass with a property readyForRendering and do the fade-in animation (which you already know how) when it is set to true. Make your existing UIView subclasses subclass of this new UIView subclass and set readyForRendering as needed.
This isn't something that can be done via appearance proxies, but you can subclass UIView and override its method (or create an extension with a new method) addSubview() method to perform the animation.
UIButton provides several methods for changing appearance for particular state, e.g.
UIButton setTitle:(NSString *) forState:(UIControlState)
but what to do when there is no dedicated method?
for example I want to change center or frame of button image or label:
button.titleLabel.frame = CGRect(...)
The frame of label changes. But when user taps the button layout glitches because frames for other states had not been changed.
Is there any way better than handling all events and setting attributes in handler method?
Frame of the label is just an example - it could be many other things like background color of text label.
I have a button and multiple labels placed over the button in storyboard. For the button I specified a default and a highlight state. Also for the labels I specified the highlight color in storyboard.
However on button press the font color of the label does not change to white. Am I missing something? I would like to configure this behavior in storyboard, not programmatically. Is this possible? Or do I have to create a custom button?
The problem is that the UILabel does not get the touch events because it simply does not handle touch events by design, it's just for showing text.
You might want to create a subclass of a UIButton but this is not a good idea since it's kind of a cluster class.
Best way to do it is creating a custom button class by subclassing either UIControl or UIView. With the later you could add it in your storyboard by changing their class to one of your button subclasses. In the subclass make your customizations in the initWithCoder: method.
If you decided to choose the UIControl way of doing this. Look at setHighlighted: method:
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted: highlighted];
// Highlight your labels here
}
Useful link: UIControl Class Reference
Is it better - better in the sense of not getting rejected from the Apple store - when trying to create a custom* UIToolbar to either:
Option A
Add the oversize middle button as a UIButton to the self.navigationController.view this is key as I'm adding a UIButton to the navigationController which seems to contradict the apple docs
Use UIToolbar appearance to implement the custom background
Option B
Create a UIToolbar and add it as a subview of the current ViewController in UINavigationController
Add the UIButton as a subview of the current ViewController in UINavigationController
Use UIToolBar's method setBackgroundImage to add the custom background
*Custom background, Oversized middle button
This is the shape of the toolbar:
Extra details: This app is for iOS 5.X or greater. It uses UINavigationController. Key challenge is that a section of the app hide/shows the navigationbar depending on the state of the app.
Option A means I don't have to workout where to place the UIToolBar, it's a challenge to work out where to place the UIToolbar because a) if I'm showing or hiding the navigationBar this shifts everything up/down vertically b) iPhone 5 with extra vertical space - I can't use autolayout as I'm support iOS 5 and I haven't really worked out how to use autoresizing masks. I'mu using hard coded "magic" numbers.
I wouldn't do either of those.
UIToolbar is nice when you want to do what it does, and it does allow some basic customization. But in this case you want a toolbar-like view that draws itself in a way that UIToolbar doesn't seem to allow for. You probably know exactly what items you want to appear in your "toolbar", and it's unlikely that you'll need to handle arbitrary assortments of UIBarItems.
So, instead of giving yourself a headache trying to force UIToolbar to do something that it was never designed for, just create a simple view containing your background image (part of which will be transparent). Place some image-based UIButtons in the view, and call it a day. It wouldn't be a bad idea to create a custom UIView subclass representing your toolbar so that all the setup is nicely packaged up in one place, and so that you can reuse the toolbar in multiple views if you need to.
I have to change the label of a UISwitch from ON-OFF to YES-NO.
I want this method to be implemented in separate class and then accessed by other classes.
I have tried to implement the snippets provided in the cook book, but without success
you can use images for on and off
#property(nonatomic, retain) UIImage *offImage;
#property(nonatomic, retain) UIImage *onImage;
image size is of 77*27
UISwitch uses images for drawing. To change the text of a UISwitch, you would have to set the onImage and offImage properties of the UISwitch to use images with your custom text. This could be done directly on a UISwitch instance, or using UIAppearance to set your custom image across all UISwitch instances in your app:
[[UISwitch appearance] setOnImage:onImage];
[[UISwitch appearance] setOffImage:offImage];
Unfortunately, setting custom on and off images for UISwitch is not functional in iOS 7 or later. From the documentation:
In iOS 7, this property has no effect.
In iOS 6, this image represents the interior contents of the switch. The image you specify is composited with the switch’s rounded bezel and thumb to create the final appearance.
And it has not been marked as deprecated. In iOS 8 this still seems to be the case, unfortunately. Customizing the colors of a UISwitch still works, but using custom images does not. To customize the images (and thus text) of a switch you will have to use a custom control class.