Problem when scrolling ScrollView control? - iphone-sdk-3.0

I have a problem with my UIScrollView. It's visible but I can't scroll it.
CGRect frame = CGRectMake(20, 90,280,1000);
scroll1=[[UIScrollView alloc]initWithFrame:frame];
scroll1.contentSize = CGSizeMake(280,1000);
scroll1.backgroundColor=[UIColor grayColor];
//scroll1.delegate=scroll1;
[scroll1 setUserInteractionEnabled:TRUE];
[scroll1 setPagingEnabled:TRUE];
[scroll1 setScrollEnabled:TRUE];
[scroll1 showsVerticalScrollIndicator];
Thanks in advance.

You've set the frame to the same width and height as the content.
Try a smaller frame like (20, 90, 200, 300).

Related

Changing the size of a Round Button in Cocoa

Is there a way by which I can increase the size of a Round Button in Cocoa? I am doing a Cocoa Application in which one of the view contains some of the user's avatars. I would like to use a Round Button and set the images to it. But I can't find any way to increase the size of the Round Button.
Is there some way of doing it?
yourButton.frame = CGRectMake(0, 0, 20, 20);
//or
yourButton.frame = CGRectMake(0, 0, 40, 60);
//or
yourButton.frame = CGRectMake(0, 0, 100, 80);
To resize the Rounded Rect NSButton you need to customize and you need to draw your own button.
To solve your problem use Gradient button resize what you want and setImage:an image should be rounded rect. then make borderless button
[button setBordered: NO];
now it will appear like rounded rect button.
To remove gray highlight use
[[button cell] setHighlightsBy:0];
Try this...
UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 150, 60)];
myButton.enabled = YES;
myButton.backgroundColor = [UIColor lightGrayColor];
[myButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[myButton setTitle:#"My Button" forState:UIControlStateNormal];
[self.view addSubview:myButton];
Change the 150 and 60 values to alter the shape of your button.
In case you are using images, they try with UIButton's method setBackgroundImage:forState:.
With this method, whenever you change the frame, it will adjust the image according to that.

Why UIActivityIndicatorView is not showing on UIWebView?

Code:
CGPoint centerPoint = [_inner_web_view center];
CGRect frame = CGRectMake(centerPoint.x, centerPoint.y, 100, 100);
_activity_indicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[_activity_indicator setFrame:frame];
[_inner_web_view addSubview:_activity_indicator];
What I need is to display ActivityIndicator on UIWebView.
Even after using [_activity_indicator startAnimating] nothing happens. :(
Can someone help me find out WHY this happens?
Your Activity Indicator View's Style is White UIActivityIndicatorViewStyleWhite and UIWebView also has white background when loading. Try Gray Style UIActivityIndicatorViewStyleGray.

UIScrollView, paging and rotation: Second view is not aligned properly after rotation

I am using a UIScrollView with Paging enabled and the following code to add subviews (core plot charts) to it.
The horizontal scrolling between the views works properly.
However, when showing the second view and then rotating from landscape to portrait mode, the second view is shifted partly to the right and a portion of the first view's right hand side is shown on the left side, hence "destroying" the paging mode.
Could you help me with these issue please? I tried many alternatives, but can't find my bug. Thank you so much!
This is how my iPad screen looks after rotating to portrait mode with the second view:
:
This is my viewDidLoad method:
- (void)viewDidLoad {
self.scrollView.contentSize = CGSizeMake(768 * 2, 400);
chart1 = [[CPTGraphHostingView alloc]initWithFrame:CGRectMake(0, 0, 768, 400)];
chart2 = [[CPTGraphHostingView alloc]initWithFrame:CGRectMake(768, 0, 768, 400)];
self.scrollView.autoresizesSubviews = NO;
chart1.autoresizesSubviews = YES;
chart2.autoresizesSubviews = YES;
self.scrollView.contentOffset = CGPointZero;
self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth ;
chart1.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth ;
chart2.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth ;
[self.scrollView addSubview:chart1];
[self.scrollView addSubview:chart2];
}
This is how I have implemented rotation:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (UIDeviceOrientationIsPortrait(fromInterfaceOrientation)) {
self.scrollView.contentSize = CGSizeMake(704 * 2, 400);
chart1.frame = CGRectMake(0, 0, 704, 400);
chart2.frame = CGRectMake(704, 0, 704, 400);
}
else {
self.scrollView.contentSize = CGSizeMake(768 * 2, 400);
chart1.frame = CGRectMake(0, 0, 768, 400);
chart2.frame = CGRectMake(768, 0, 768, 400);
}
}
I think you should change the contentOffset of the scrollview when rotation is taking place.
You should have a way to know which page is currently displayed before rotation (maybe put this information in a variable). Then in your didRotate.. method set the contentOffset of the scrollview after resizing it, like this:
CGFloat offset = self.scrollView.frame.size.width * currentPageIndex;
[self.scrollView setContentOffset: offset];
As an alternative to laying out your subviews in your view controller, have you considered subclassing your UIScrollView and overriding it's layoutSubviews method? You might also consider defining your dimensions as percentages rather than fixed points - because the point values will shift according to rotation and presence of other UI elements such as navigation and toolbars. You may run into trouble as you're manually resizing UI elements in your rotation method, at the same time that the UI is going to be attempting to automatically resize elements according to your resizing masks. Just my thought...

Positioning UIViews within UIScrollViews

I have added 9 UIViews as subviews of UIScrollView with the below code:
-(void)constructedViewsForArray:(NSArray*)_listOfItems {
[_scrollView setContentSize:CGSizeMake(_listOfItems.count * 160, _scrollView.frame.size.height)];
CGRect frame = CGRectMake(10, 5, 100, 90);
for (int i = 0; i<[_listOfItems count];i++) {
UIView *aView = [[UIView alloc]init];
UILabel *test = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, 100, 20)];
test.text = [NSString stringWithFormat:#"%#",[_listOfItems objectAtIndex:i]];
[aView addSubview:test];
[aView setBackgroundColor:[UIColor redColor]];
frame.origin.x=((frame.size.width+5)*i+5);
aView.frame = frame;
[_scrollView addSubview:aView];
}
}
The view's are added correctly to the scrollview.But after scrolling the UIView's are not aligned. Please refer to the images below:
The 5px space between the first view and the screen edge is missing after scrolling.
How can I set the view positions after scrolling.
PS: Paging is enabled.
Thanks for any help.
Regards,
iSee
I think what you are missing is that there need to be 10 px between 3 and 4, and 6 and 7, etc. for paging to work like you want it.
So changing the line
frame.origin.x=((frame.size.width+5)*i+5);
to something like this
frame.origin.x=((frame.size.width+5)*i+5 + (i/3) * 5);
It looks you are not noticing that the 4th column requires 10 px margin.so you need to add 5 additional pixel after 3rd column.
if((i%3)==0)
frame.origin.x=(((frame.size.width+5)*i+5)+ (i*5));
else
frame.origin.x=((frame.size.width+5)*i+5);
I hope this will help.

UIScrollView Isn't Scrolling

Every time this question gets asked on SO (and elsewhere) the answer is "make sure the contentSize is larger than the view size, and set it in viewDidLoad!" Yes, I'm doing that, so what else could be the problem?
In my controller's loadView: I have these lines to set up my view:
descriptionView = [[DetailDescriptionView alloc] initWithFrame:CGRectMake(160, 60, 160, 180)];
descriptionScrollView = [[DetailDescriptionScrollView alloc] initWithFrame:CGRectInset(CGRectMake(0, 0, 160, 180), 5, 5)];
[descriptionView addSubview:descriptionScrollView];
[self.view addSubview:descriptionView];
Then, in viewDidLoad, I have this code:
[descriptionScrollView setDescriptionText:#"<lots of text that will require scrolling>"];
NSUInteger contentHeight = <** calculations on the text to determine height **>
[descriptionScrollView setContentSize:CGSizeMake(descriptionScrollView.frame.size.width, contentHeight)];
NSLog(#"ContentSize: %#", NSStringFromCGSize(descriptionScrollView.contentSize));
NSLog(#"DescriptionScrollView Size: %#", NSStringFromCGRect(descriptionScrollView.frame));
Those NSLogs confirm all should be fine:
ContentSize: {150, 330}
DescriptionScrollView Size: {{5, 5}, {150, 170}}
When it comes to doing the actual drawing of the text, I'm using Core Graphics in the scrollview's drawRect: method. Here's the relevant snippet:
CGRect descriptionTextBox = CGRectMake(self.frame.origin.x, 20, self.frame.size.width - 10, 330);
[self.descriptionText drawInRect:descriptionTextBox withFont:[UIFont fontWithName:kMediumFontName size:kFontSizeMicro]];
I think that covers what I'm trying to do. The scrolling just doesn't occur. Can anyone recommend a tactic to figure out what to try to make this work?
You're drawing in the scrollview's draw rect; it needs to be in a subview of the scrollview.