This question already has answers here:
How to Change the UISlider to Vertical?
(4 answers)
Closed 8 years ago.
How can I make a vertical UISlider? I saw it in one of the applications and was trying to duplicate it. But seems difficult, does anyone know how?
The easiest approach is to simply rotate the slider. This can be done by using CGAffineTransformMakeRotation to create a transform and apply that to the slider's transform property. Just remember that the function takes radians.
In case you use auto layout:
In your viewDidLoad, try:
UIView *superView = self.sizeSlider.superview;
[self.sizeSlider removeFromSuperview];
[self.sizeSlider removeConstraints:self.view.constraints];
self.sizeSlider.translatesAutoresizingMaskIntoConstraints = YES;
self.sizeSlider.transform = CGAffineTransformMakeRotation(M_PI_2);
[superView addSubview:self.sizeSlider];
It does not work with constraints, so the trick is to remove the constraints for your uislider.
You might have to resize it manually by setting its frame property.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to do some thing like this,
How to draw a circle in UILabel which looks similar to this image, i just want to avoid using an image instead.
I'd suggest adding a shape layer to the UILabel. Something like this:
// Create the shape layer
CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 50, 50)].CGPath;
circleLayer.fillColor = [UIColor clearColor].CGColor;
circleLayer.strokeColor = [UIColor whiteColor].CGColor;
circleLayer.lineWidth = 1;
// Add it do your label's layer hierarchy
[label.layer addSublayer:circleLayer];
That'll give you the greatest control over its appearance and that of the font for the A.
UPDATE:
It's just occurred to me that you'll struggle to get the "A" vertically offset in order to put a circle around it. There are hacks to get vertical centering in a UILabel, but you'd be much better off using a UITextField instead, since it supports the contentVerticalAlignment property. You just need to set its userInteractionEnabled to NO to prevent user from typing text on it!
Other than that, the principle of adding the CAShapeLayer is the same.
You can achieve this by the way #maddy suggested or, create UILabel with square rect, put text alignment to the middle and use label's layer's cornerRadius with borderWidth. Just set cornerRadiusto the half width (or height) of the label. Good Luck!
This question already has answers here:
UILabel text margin [duplicate]
(38 answers)
Closed 9 years ago.
I'm trying to indent the text in a UILabel to leave some margin around the text showing the background colour. Following the suggestion here I've overriden textRectForBounds:limitedToNumberOfLines: like so:
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines
{
CGRect intermediate = CGRectMake(bounds.origin.x+MARGIN,bounds.origin.y+MARGIN,bounds.size.width-2*MARGIN,bounds.size.height-2*MARGIN);
return [super textRectForBounds:intermediate limitedToNumberOfLines:numberOfLines];
}
But no matter what I do, the text ends up tight against the left border of the rectangle. It seems as though the drawing is ignoring the origin part of the returned CGRect (although it seems to be respecting the width part, as if I reduce to width of intermediate to eg bounds.size.width-200 the rect that textRectForBounds returns is suitably narrow and the text is drawn in a long skinny column).
So: what else I need to do to the UILabel to make the drawing respect the textForRectBounds-returned-rect's origin.x and origin.y? I'd rather not override UILabel's drawTextInRect if I can help it.
Update: This was a long time ago and I can't remember exactly why the other question didn't work for me. I believe it was because I was trying to have a UILabel with multiple lines, and the solution here didn't work in that case.
I think you should override both textRectForBounds:limitedToNumberOfLines: and drawTextInRect: like this:
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines
{
return CGRectInset(bounds, MARGIN, MARGIN);
}
- (void)drawTextInRect:(CGRect)rect
{
[super drawTextInRect: CGRectInset(self.bounds, MARGIN, MARGIN)];
}
Check the documentation, it might be of some help. calls to super might not be returning the values you assume.
You should not call this method
directly. This method should only be
overridden by subclasses that want to
change the receiver’s bounding
rectangle before performing any other
computations. Use the value in the
numberOfLines parameter to limit the
height of the returned rectangle to
the specified number of lines of text.
For this method to be called, there
must be a prior call to the sizeToFit
or sizeThatFits: method. Note that
labels in UITableViewCell objects are
sized based on the cell dimensions,
and not a requested size
The default implementation of this
method returns the original bounds
rectangle.
Good luck!
hi i am new to iphone.I need to scroll scrollview horizontally instead of vertical.Is it possible to scroll horizontally.If it possible pls post link consist sample example.Thank u in advance.
you can use following code
[myscrollview addSubview:imgButton];
x = frame.origin.x;
y = frame.origin.y+80;
[myscrollview setContentSize:CGSizeMake(x,y)];
in that each time you add a new button/Image increase content size Y position and also make set scroll vertical false.
EDIT: Here is the link to your question.
It's hard to answer you without a concrete example. In general, the scrolling directions of a UIScrollView are defined by it's "contentSize" property. So if you have a label (myLabel) which is wider than your scrollView (myScrollview) you could write this:
myScrollview.contentSize = CGSizeMake(myLabel.frame.size.width, myScrollview.frame.size.height);
//Next line is rather optional, should be already set by default
myScrollview.scrollEnabled = YES;
If you want an example, here the sample codes are.
As Phlibbo said, the contentSize of scrollView will decide the direction of that.
In viewDidLoad, I can create a gradient with no problem:
CAGradientLayer *blueGradient = [[CAGradientLayer layer] retain];
blueGradient.frame = CGRectMake(gradientStartX,gradientStartY,gradientWidth,gradientHeight);
where gradientWith is device-defined as 320 or 1024 as appropriate.
What I can’t do is resize it inside willRotateToInterfaceOrientation: -– and thus get rid of that empty black space off to the right -- after the user changes to landscape mode. (The nav bar and tab bar behave nicely.)
(1) Recalibrating the gradient’s new dimensions according to the new mid-point, (2) using kCALayerMaxXMargin, and (3) employing bounds all looked like they would do the job. bounds looked a litte more intuitive, so I tried that.
I don’t want to admit that I have made zero progress.
I will say that I’ve been reduced to the brute force method of trying every permutation of self, view, layer, bounds, blueGradient, and CGRect(gradientStartX,gradientStartY,newGradientWidth,newGradientHeight) with zero success.
This is not difficult. My lack of understanding is making it difficult. Anyone out there “Been there, done that”?
Does the layer resize its size automatically? If so, simple
[blueGradient setNeedsDisplay];
should do the trick.
Hope this was helpful,
Paul
I have some buttons in an UIView. My problem is, that they get cut
off at the right side of the UIView. How do I prevent this?
alt text http://img.skitch.com/20090629-mj32p1bkff476256pwrpt69n2d.png
I've checked already Interface Builders clip property, but it's no
solution for this problem.
Regards
It seems like either you made these buttons programmatically, or you reiszed the initial IB view window to be larger and expected it to shrink down to the fit the screen.
The buttons in question cannot fit on the screen as they are - what effect are you looking for?
If you want the buttons all to fit you could set the text size to be smaller, and then they could fit.
If you want the buttons the size they are then you'll have to make another row, or put the buttons into a side scrolling container.
I have been using java and only recently began learning Apple's Obj-C framework.
An alternative to scrolling and row-breaking is using a "grid" layout with 1 row and n columns, where n is the number of buttons. Each cell has a fixed size. And you will have to resize your buttons (the subviews) in your superview's setNeedsLayout: method to whatever width you need such that all buttons fit the row.
See java's GridLayout class.
Kendall, thanks for your answer.
Here is my solution:
if(previousFrame.origin.x + theStringSize.width > 220){
roundedButton.frame = CGRectMake(15, previousFrame.origin.y + 30 , theStringSize.width + 8, theStringSize.height);
[myContainer insertSubview:roundedButton belowSubview:[tagsContainer.subviews lastObject]];
}else {
roundedButton.frame = CGRectMake(previousFrame.origin.x + previousFrame.size.width + 5, previousFrame.origin.y, theStringSize.width + 5, theStringSize.height);
[myContainer insertSubview:roundedButton belowSubview:[tagsContainer.subviews lastObject]];
}
I calculate, how many pixel I've moved from the left side. At some threshold (in my case 220) I start a new line.