I have an issue with scroll view. I have implemnted two font resize buttons to increase or decrease text font size for the text view embedded in the scroll view. But after decreasing font size, I calculate the scroll view content and reize it to adapt to the new text view height. But every time I modify text font, it scrolls down for every step.
Here is the code:
- (IBAction)decreaseText:(id)sender {
int MyTextSizeMin = 8;
int MyTextSizeMax = 20;
// disable buttons when they're out of the range.
BOOL smallerEnabled = textFontSize > MyTextSizeMin;
BOOL biggerEnabled = textFontSize < MyTextSizeMax;
[self.decreaseText setEnabled:smallerEnabled];
[self.increaseText setEnabled:biggerEnabled];
height =0;
CGFloat secondLabelsize = texto.font.pointSize;
[texto setFont:[UIFont systemFontOfSize:(secondLabelsize-1)]];
CGRect frame = texto.frame;
frame.size.height = texto.contentSize.height;
self.texto.frame = frame;
height +=texto.contentSize.height;
height += self.imagen.image.size.height;
height += self.fecha.frame.size.height;
height += self.titulo.frame.size.height;
height += 200;
self.scrollView.contentSize=CGSizeMake(300.0,height);
[self.scrollView setNeedsDisplay];
}
How can I disable this undesired scroll?
Many thanks!
Try it may it help full for you.
[scrollView scrollRectToVisible:CGRect animated:BOOL];
Related
I have a UIView named CalendarUIView. I placed it inside of a view controller called MainHubViewController. I want to make it so that the CalendarUIView's height and width are half of the parent's (MainHubViewController) height and width. So for example, MainHubViewController's dimensions are 400 by 500. Then I want CalendarUIVIew's dimensions to be 200 by 250.
I put this into my viewdidload method and it didn't work :(
self.CalendarUIView.bounds.size.height = self.view.bounds.size.height / 2.0f;
Any solutions?
Thanks
To change the frame you can do this,
view.frame.size = CGSize(width: someW, height: someH)
However, you will keep the same origin point so with will be off centre.
So either change the centre point, using .center for the view to match your superview. Or set the frame from the beginning, with takes a CGRect
PS sorry its in Swift the the idea is the same
You should use CGSizeMake
self.CalendarUIView.frame.size = CGSizeMake(your width, your height);
This should give you the idea
//Get the parent size
CGRect *containerFrame = self.MainHubViewController.frame;
float height = containerFrame.size.height;
float width = containerFrame.size.width;
CGRect newFrame = self.CalendarUIView.frame;
newFrame.size = CGSizeMake(width / 2, height / 2);
self.CalendarUIView.frame = newFrame;
I would like to know the width of the dark grey frame on either side of the inside picker part and the width of the separators between components. This would be at default settings (eg. what's shown in the .xib). Or, how to find such values programmatically. Thank you
To clarify, I'm looking for what the "suggested minimums" might be for those values. I'm putting my UIPickerView in a popover, and the UIPickerView is wider than 320 px (which is what the .xib gives as the "default"). I would like to know these values so I can add them to the popover's width to make sure it doesn't cut off components on the right side of the UIPickerView.
Well this can be a little tricky since the Picker can have a dynamic number of components. So in order to find the widths you have to take into account the number of components. This can be done like so:
NSInteger n = picker.numberOfComponents;
const CGFloat separatorWidth = 8.0f;
const CGFloat sectionExceedWidth = -2.0f;
CGFloat totalWidth = picker.bounds.size.width;
CGFloat panesWidth = totalWidth - separatorWidth * (n - 1);
for (NSInteger i = 0; i < n; i++) {
CGFloat sectionWidth = [picker rowSizeForComponent:i].width + sectionExceedWidth;
panesWidth -= sectionWidth;
}
CGFloat leftPaneWidth = ceilf(panesWidth * 0.5f);
CGFloat rightPaneWidth = panesWidth - leftPaneWidth;
CGFloat totalHeight = picker.bounds.size.height;
CGRect totalRect = CGRectMake(0, 0, totalWidth, totalHeight);
Where the left and right panes widths are found and the separator size is static.
This was pulled from here.
- (void)viewDidLoad
{
[super viewDidLoad];
objectiveLabel.text = objectstring;
objectiveLabel.lineBreakMode = UILineBreakModeWordWrap;
objectiveLabel.numberOfLines = 0;
[objectiveLabel sizeToFit];
vocabularyLabel.text = vocabularystring;
vocabularyLabel.lineBreakMode = UILineBreakModeWordWrap;
vocabularyLabel.numberOfLines = 0;
[vocabularyLabel sizeToFit];
}
Can Someone point me to the right direction on how to get Label 1 to push or move Label 2 instead of overlapping?
If you want to "push or move" a UILabel, you just set the frames accordingly. So look at objectiveLabel.frame, add the objectiveLabel.frame.origin.x plus objectiveLabel.frame.size.width, and that's the minimum of what you should set vocabularyLabel.frame.origin.x to. If you want vocabularyLabel to adjust for the width of not only the objectiveLabel frame width, but actually to tweak according to how objectstring will be rendered in objectiveLabel, you calculate the size of objectiveLabel's width by:
CGSize size1 = [objectstring sizeWithFont:objectiveLabel.font
constrainedToSize:objectiveLabel.frame.size
lineBreakMode:objectiveLabel.contentMode];
CGRect frame2 = vocabularyLabel.frame;
frame2.origin.x = objectiveLabel.origin.x + size1.width;
vocabularyLabel.frame = frame2;
This won't factor in the minimumFontSize of the labels, though. But if the minimumFontSize is the same size as the font size, then you should be golden.
What you want is called Auto Layout.
I'm new to iPhone development, coming from a web application development background and I'm working on my first project. I chose to create a Navigation based project, since after reading it seemed to be the easiest way to get what I'm after. How do you change the width of the UITableView? Eventually, I'd like to have a top bar, UITableView, and bottom bar be 304px wide. I've tried the following in my RootViewController's viewDidLoad method, but I'm doing it wrong:
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.size.width = 200;
self.tableView.frame = tableViewFrame;
Thanks for any help in advance.
If you want to change the width of the tableViewCell.. go to cellForRowAtIndexPath, and assign it there.
You could also do -
CGFloat tableBorderLeft = 1;
CGFloat tableBorderRight = 1;
CGRect tableRect = self.view.frame;
tableRect.origin.x += tableBorderLeft; // make the table begin a few pixels right from its origin
tableRect.size.width -= tableBorderLeft + tableBorderRight; // reduce the width of the table
tableView.frame = tableRect;
For changing the size of header
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
return 150.0; //Give a value
}
For changing size of footer
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 150.0;//Give a value
}
I am trying to figure out the best way to create a view like the app details screen in the AppStore app. I want a thumbnail and text content under it that all scrolls if the content is too long. Is this done in a tableview or a scrollview?
I've made one in a scrollview. I calculated the size of each element's frame from this method:
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
I kept a running total of the y size by adding it on after each label. At the end, if the scroll view was over a certain size (the length of my page) I gave that size to the scroll view, adding a little on the end so it wouldn't bump against the bottom.
Here's some code:
int currentYPos;
CGSize maximumSize = CGSizeMake(300, 9999);
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleDefault;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = NO;
// set the title frame size
self.titleLabel.text = self.title;
CGSize titleSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font
constrainedToSize:maximumSize
lineBreakMode:self.titleLabel.lineBreakMode];
currentYPos = titleSize.height + 20;
CGRect titleFrame = CGRectMake(10, 0, 300, currentYPos);
self.titleLabel.frame = titleFrame;
Note that many of the titleLabel properties were set on a label in IB.