I've got a UISlider in my main view, but it doesn't receive touches at the right end. I thought it could be a pesky view covering it, but it definitely isn't. Has anyone got any other ideas?
I guess your UISlider fell out of bounds of the superview. Try to set background of UISlider superview to some color and check it out.
Its in your control to set the height and width of UISlider, using CGRectMake... and its touch sensitive till the given width.. i think u would have missed writing the below option...
silder_Obj.userInteractionEnable = YES;
Just try it out.. it had worked for me.
I found out that in my case, the issue occurred when the right/left border of the UISlider matched its superview's corresponding border. Making the superview wider so that there would be 5.0-10.0 distance between their borders solved the issue for me.
Related
i'm looking for the perfect place in my code to set rounded cornerRadius to my views.
Sometimes it seems like the UI shrinks my view after i set the cornerRadius to frame.height/2 so im getting a "more then round" view (looks like an eye)
I'm building my App with Interface Builder, so I thought viewDidLoad should be the right method to call myButton.layer.cornerRadius = myButton.frame.height/2
I also tried to design my views in viewDidLayoutSubviews but there were also some strange results
So my general question is:
Where should I place my cornerRadius code to be sure that I'm getting the right result?
Thanks for your replies!
EDIT:
The problem is especially with buttons (or views) with proportional height to superview. With fixed height its working fine!
Have you only placed the myButton.layer.cornerRadius = myButton.frame.height/2 in viewDidLoad?
If placed it in both views then remove it from subviews.
And make sure that the button is a "Square" in Size. I mean height and weight are equal.
I have added the UIImageview to the viewcontroller which was presented modally,my problem was when i rotate the device imageview disappearing.I am facing this problem in iPad when rotated in all orientation,but some time can able view the image.I was wondering with this issue.
Any help would be appreciated.
Thanks in advance .
It could have to do with Autolayout. Ensure that you have your constraints set properly. I.e. maybe set the distance of the top position to the superview and the leading position to the superview properly.
I'm running into something weird when using UIDatePicker elements with Storyboards in iOS 7. In the Storyboard, the date picker has a fixed height of 162. In reality, however, the element takes up more space than that. So this
turns into this:
so I have to move everything below it down, guessing and eyeballing how much space the date picker will actually use. Is this a bug? Am I doing something wrong? To be clear, the date picker is totally transparent - can't figure out a way around that. The white background at the top is the main UIView, and the gray background is the background of the UITableView embedded inside the container view.
I can confirm that using UI(Date)Picker in storyboards has a different height (162.0) than in "reality" (216.0). Therefore you have to adjust the space to container view to fit that "real" date picker height or try to solve it using auto-layout.
Here is a funny trick I just found: put the UIDatePicker inside a dedicated view with a constraint of 162 points in height (add 0 point vertical constraints from top and bottom of the picker to this new superview). This seems to have the effect of forcing the picker to keep the size of 162 points.
You can add the option of clipping the subviews to be sure that the UIDatePicker will not escape from its new prison.
EDIT: after some more tests, it seems that by just adding a height constraint of 162 points to the UIDatePicker, it will keep its "IB size". And, to answer #Andrew's comment, here is what it will look like:
You can change the width and height by simply giving it width and height constraints. Without doing that, the UIDatePicker just acts weird, I've found.
Setting clipsToBounds property to YES on my UIDatePicker object helped me.
datePicker.clipsToBounds = YES;
For XIB's you can directly tick the checkbox for Clip Subviews :
I'm trying to rotate a UILabel by 45 degrees. I'm setting the transform property to CGAffineTransformMakeRotation(M_PI * 0.25) but when I do so the UILabel just disappears. If I change 0.25 to 0.26, I can see a glimpse of the UILabel (see below)
UILabel before rotation:
Code: self.myLabel.transform = CGAffineTransformMakeRotation(M_PI * 0.26);
If I missed any information that might be helpful, please let me know!
Update
It seems that the frame must be set before applying the rotation.
Your code should work fine, so something else is going on that you didn't post code for. I'd recommend checking the autoresizing mask as well as anywhere else that may be manipulating the transform. From the appearance and your description, it almost seems like it is being rotated along the wrong axis via a 3D rotation causing you to view the label side on where it has a zero width/thickness, like looking at the edge of a paper head on.
Another solution to the problem may be with embedding your UILabel within another view and using the outer view to position the label on your screen.
Another post had mentioned the problem that I'm seeing with distortion or disappearing of the text in a UILabel. Their solution was to set all the outer springs on the UILabel. This worked for me, but then my label wasn't positioned properly on screen, especially during device rotation. So I thought embedding my UILabel in a container view would let me use the container view to position my label with just the top and right spring set while still allowing proper rotation of the UILabel within with the CGAffineTransformMakeRotation.
Hope this helps out someone else who is also having this problem.
I have a UIView in which I need to draw text in drawRect:
- (void)drawRect:(CGRect)rect {
...
[#"some text" drawAtPoint:somePoint withFont:someFont];
...
}
Because the text requires special formatting, I cannot just use a UILabel.
It looks fine until I rotate the device. Then the size of my custom UIView changes (in the parent view's layoutSubviews method), and the text becomes stretched in one direction and squished in the other.
When I replace my view with a UILabel, the text always looks great, even when the bounds of the view changes.
How can I get my view to exhibit the same behavior as UILabel?
Some things I have looked into, but have yet to have success with:
Set the view's layer's needsDisplayOnBoundsChange to YES.
Set the view's contentStretch to CGRectZero.
Call setNeedsDisplay in my view's layoutSubviews.
Maybe I'm not doing one of these things right. Has anyone else run into this?
Update: As recommended in James Huddleston's answer, I set the contentMode property of the view to UIViewContentModeRedraw, which got me part of the way there. The text now appears correct at the conclusion of the animation. However, at the start of the animation the text gets squished/stretched to fit the end dimensions and then gets unsquished/unstretched over the course of the animation. This is not the case with UILabel.
Try setting the contentMode property of your view to UIViewContentModeRedraw.
This seems to work OK:
self.contentMode = UIViewContentModeRedraw;
self.contentStretch = CGRectMake(1, 1, 0.5, 0.5);
And then ensure that the bottom-right pixel is the background color. To do that, I put one pixel of padding around the contents of the view. It seems like UILabel doesn't have the one pixel border restriction, so it must be doing something different. But as far as I can tell, this has the same effect.
Use a UIWebView
Sounds a bit overkill but it seems the recommended way to get formatted text that's more complicated than a UILabel can cope with.
There is some source code created by Kevin Ballard called FontLabel. (code.google.com)
The good thing about this, it subclasses UILabel and you can use your own Font ;)
//EDIT: ok ok, as told I will update my answer to recommend subclassing UILabel "to get all the UILabel goodness" ^^