Here I am using a two pie chart and it having a pagination.My problems is in landscape mode the pie chart have move every where in iphone screen. Please be give any idea to scroll in landscape mode
[self.view setFrame:CGRectMake(0, 0, 480, 320)];
[myScrollView setFrame:CGRectMake(0, 0.0, 480, 290-40)];
[myScrollView setContentSize:CGSizeMake(480*2, 400.00)];
[myScrollView setContentOffset:CGPointMake(480*currentPageTop, 0.00)];
[pageControl setFrame:CGRectMake(0.0, 30.00, 480, 20.00)];
[pageControl setCurrentPage:currentPageTop]
Related
I have an app which is not using auto layout. Instead I'm using autoresizingMask. It works well in iOS 7. And it also works fine in iOS 8 when I start the app in portrait mode (it's still fine even when I rotate the device afterwards). Here is the screenshot when it's correct:
Here is my source code:
CGFloat w = [[UIScreen mainScreen]bounds].size.width;
CGFloat h = 100;
CGRect rect1 = CGRectMake(0, 0, w, h);
UIView* view1 = [[UIView alloc] initWithFrame:rect1];
view1.backgroundColor = [UIColor yellowColor];
view1.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:view1];
CGRect rect2 = CGRectMake(10, 105, 748, 50);
UIView* view2 = [[UIView alloc]initWithFrame:rect2];
view2.backgroundColor = [UIColor purpleColor];
view2.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:view2];
The problem occurs when I start my app in landscape mode. Here is the screenshot:
Can anybody tell what I did wrong in my code? Thanks
I modified the code a bit:
CGRect rect2 = CGRectMake((w-748)/2, 105, 748, 50);
This works as I expected.
I've tried everything and read a LOT about using a CALayer in a NSView, but can't get code that worked fine on iOS to work on a Mac.
I'm calling
[ nsView setLayer:[CALayer layer]];
[ nsView wantsLayer];
to create a layer as I've read everywhere I should.
then I've tried settings the layer's background color, and adding a sublayer and setting it's background color, but I just get a black window no matter what I do.
The entire programatically created app is, after removing all nibs etc, trying to make a gradient to be sure I get some Layer content:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSWindow *mainWindow;
NSView *nsView;
mainWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(20, 500, 200, 400)//screenRect
styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[mainWindow setTitle:#"My Window"];
CAGradientLayer *layer;
nsView = [ [ NSView alloc] initWithFrame:NSMakeRect(20, 20, 200, 400)];
[mainWindow makeKeyAndOrderFront:nil];
[ nsView setLayer:[CALayer layer]];
[ nsView wantsLayer];
[ nsView setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawOnSetNeedsDisplay];
layer = [CAGradientLayer layer];
layer.frame = CGRectMake(0, 0, 200, 400);
layer.colors = #[ (id)CGColorCreateGenericRGB(1, 0, 0, 1), (id)CGColorCreateGenericRGB(1, 1, 0, 1) ];
layer.startPoint = CGPointMake(0.5, 0);
layer.endPoint = CGPointMake(0.5, 1);
[nsView.layer addSublayer:layer];
[layer setNeedsDisplay];
[nsView setNeedsDisplay:YES];
[mainWindow setContentView:nsView];
}
no matter what I do, I never get any indication that the layer is being used. It and subviews exists when I debug, but are never shown. The view's drawRect method is called once as well.
I've read for days about using CALayers for NSViews, but nothing seems to get them working.
Any suggestions?
It was something amazingly simple but easy to be blind about:
I was calling:
[nsView wantsLayer]
(thinking it was a way of setting wantsLayer (probably infuenced by seeing it as a property)).
Which is just a getter that was being ignored.
[nsView setWantsLayer:YES]
or
nsView.wantsLayer = YES;
would of course be what I wanted.
I have an issue where i am adding a UIScrolview to my UIViewController, but my UIScrollview doesnt want to scroll. I want it to work the same way that it works on a UITableViewController.
Here i initialize my UIScrollview
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 800)];
scroll.contentSize = CGSizeMake(320, 800);
scroll.backgroundColor = [UIColor redColor];
scroll.showsHorizontalScrollIndicator = YES;
scroll.scrollEnabled = YES;
scroll.userInteractionEnabled=YES;
[self.view addSubview:scroll];
Here i add my content to the scrollview:
UILabel *memberNo = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
memberNo.text = #"Member No";
memberNo.font = [UIFont boldSystemFontOfSize:16];
memberNo.textColor = [UIColor limeColor];
[scroll addSubview:memberNo];
memberText = [[UITextField alloc] initWithFrame:CGRectMake(10, 40, 300, 30)];
memberText.placeholder = #"Member No";
memberText.borderStyle = UITextBorderStyleRoundedRect;
memberText.text = #"1111111";
[scroll addSubview:memberText];
Try this
set content size more than the screen size and it will scroll whether there is more content or not
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 800)];
HorizontalScroll
scroll.contentSize = CGSizeMake(320, 900);
VerticalScroll
scroll.contentSize = CGSizeMake(340, 800);
As others have said, the scroll view's size (specifically, its bounds.size) must be smaller than its contentSize for it to actually scroll.
You probably want your scroll view to fit inside its superview, so try setting its frame to the superview's bounds:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds];
The content is the same size as the scrollview: there is nothing to scroll.
The scrollview needs to contain a view that is bigger than it's own size.
Try setting the contentSize to be larger than the frame. For example:
scroll.contentSize = CGSizeMake(1000, 800);
If that doesn't work, then check where you are setting the content size. Where are you initializing the UIScrollView? Try moving the above line to viewWillAppear or viewDidLayoutSubviews.
frame of the scroll view refers to the size of the scroll view itself whereas content size is the size for the view which is to be shown in the scroll view. If the size of view to be shown in scroll view is having smaller size than the scroll views frame size, then it won't at all scroll, but if you set content size more then scroll view has to scroll to show the 'extra' size more than its own frame size.
e.g. If height of scroll view is 100 and you have set the height factor in content size equal to 150, then these extra 50 pixels will be scrollable.
Good Luck!
This code seems to work well, modifying the properties of my button, except the titleLabel font color is not changing. I can change the font, font size, shadow but not the color. It currently displays as white although I am trying to set it to black. I've tried button1.titleLabel.textColor = [UIColor blackColor]; and [button1.titleLabel setTextColor:[UIColor blackColor]]; seems to recognize the property but still remains white.
[button1.titleLabel setTextColor:[UIColor blackColor]];
[button1.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[button1.titleLabel setShadowColor:[UIColor blackColor]];
[button1.titleLabel setShadowOffset:CGSizeMake(-1, 1)];
[button1 setTitle:#"Do it" forState:UIControlStateNormal];
button1.frame = CGRectMake(0, 0, 250, 40.0);
[myView addSubview:button1];
This worked.
[button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
(xCode 4.3.2, ARC, Storyboard) I have a Master/Detail project and the MasterViewController is a UITableViewController, as usual. It has a navigation bar at the top and a toolbar at the bottom. I've created a custom subview that I load programmatically in viewDidLoad.
It loads fine, and is on top just like I want, but when the user scrolls the tableview, the subview scrolls too. I need the subview to "stick" to the bottom.
Here is the code I used to add the subview:
CGRect totalFrame = CGRectMake(0, 314, 320, 58);
UIView *totalBG = [[UIView alloc] initWithFrame:totalFrame];
totalBG.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"totalBG.png"]];
[self.view addSubview:totalBG];
CGRect totalLabelFrame = CGRectMake(12, 12, 80, 40);
totalLabelBG = [[UILabel alloc] initWithFrame:totalLabelFrame];
totalLabelBG.backgroundColor = [UIColor clearColor];
totalLabelBG.text = #"Total:";
[totalLabelBG setFont:[UIFont boldSystemFontOfSize:22]];
totalLabelBG.userInteractionEnabled = NO;
totalLabelBG.textColor = [UIColor whiteColor];
totalLabelBG.shadowColor = [UIColor blackColor];
totalLabelBG.shadowOffset = CGSizeMake(0, 1);
[totalBG addSubview:totalLabelBG];
I tried setting userInteractionEnabled to NO in viewDidLoad and detecting a
touch, and setting the totalLabelBG.center property, and neither worked.
I've also read through a lot of threads on disabling scrolling for webviews, but found nothing relevant.
I found another SOF question with a response that may or may not work, but the user did not explain the answer. "The trick is to adjust the frame of the "non-scrollable" subview inside -layoutSubviews."
I achieved the desired result by adding the subview to the UINavigationController container like this:
[self.navigationController.view addSubview:totalBG];
Like in the answer above. Just add that particular subview to any subview outside on the UIScrollView instance. If its not suppose to scroll then it doesn't make sense to put it inside the scroll view to begin with. Instead make the scroll view only take up the height up to the top of the totals subview