In my app I have buttons in a UIScrollView that when they are clicked it displays text in a UITextView. In my app I can't use auto layout; but my UIScrollView won't work.
How can I use UIScrollView when I don't have "use auto layout" on?
This worked for me:
.h
IBOutlet UIScrollView *scrollerName;
.m [viewDidLoad]
[Scroller setScrollEnabled:YES];
[Scroller setContentSize:CGSizeMake(x, y)];
self->Scroller.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
or just:
[Scroller setScrollEnabled:YES];
[Scroller setContentSize:CGSizeMake(x, y)];
Related
Let me elaborate the steps i am doing
Create Mac 10.9 Project
Drag a CustomView (Let's call it myView) to the .xib
Drag a NSButton to the .xib but out side the CustomView
Now programatically (using a other class) i add a NSTextField to the CustomView when the button is clicked by this code
NSTextField *textField = [[NSTextField alloc] init];
[textField setBezeled:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[textField setFont:[NSFont fontWithName:#"Arial" size:20]];
[textField setStringValue:#"Hello World!"];
int textWidth = textField.fittingSize.width;
int textHeight = textField.fittingSize.height;
[textField setFrame:NSMakeRect(0, 0, textWidth, textHeight)];
[myView addSubview:textField];
Now i see that the TestField is added to myView
All i want is the user can drag the textField movable inside myView
i added the following code
- (void)mouseDown:(NSEvent *)event{
NSLog(#"Hi");
}
But the NSLog is not getting shown
How do i make the NSTextField draggable?
Note: Because mouse-moved events occur so frequently that they can
quickly flood the event-dispatch machinery, an NSWindow object by
default does not receive them from the global NSApplication object.
However, you can specifically request these events by sending the
NSWindow object an setAcceptsMouseMovedEvents: message with an
argument of YES.
From Apple Docset
I places a UIScrollView inside the main UIView of my viewcontroller.
Then I added some controls at the bottom of the view and a UIPageControl near the top.
When i scroll the view, the bottom controls scroll fine but the UIPageControl remains in place, so it ends up blocking the buttons and labels at the bottom.
How do I make the UIPageControl and its views scroll up or down with the rest?
Here is what it looks like
I got it to work by:
1) Putting all views/controls inside a containerView and declaring it as a property.
2) Adding this code:
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
self.scrollView.contentSize = self.containerView.bounds.size;
}
- (void)viewDidLoad{
[super viewDidLoad];
//added with containerview from g8productions
self.containerView = [[UIView alloc] initWithFrame:CGRectMake(36, 59, 900, 1200)];
self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;
[self.scrollView addSubview:self.containerView];
[self.scrollView setContentSize:self.containerView.bounds.size];
}
Now it scrolls! :)
thanks for reading. I am making a UiScrollView to show content. For some reason I am unable to scroll to the bottom of the UIScrollView to see all content. No matter what I change my [scroller setContentSize:CGSizeMake(x,x)]; to, it makes no difference... 1,1 or 10,000 , 10,000 nothing changes. Here is my code. Thanks for the help.
#interface ViewController : UIViewController {
UIScrollView *scroller;
}
#property (nonatomic, retain) IBOutlet UIScrollView *scroller;
and the .m file
#synthesize scroller, testScroll;
- (void)viewDidLoad
{
[super viewDidLoad];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(400,2000)];
}
And my scrollview's size is (331, 1875)
Thanks a lot
Try this,
myScrollView.contentSize = CGSizeMake(320, 500);
Do not forget to set scroll view delegate.
I am a newbie for MAC development, I have a simple Cocoa Application using NSViewController where I have a main view and 2 NSViewController and dynamically flipping them. I have added PDFView on NSViewController view to show pdf pages flipping at run time. but my problem when the views are added dynamically then on PDFView I can see the pdf page after resizing the window. I tried using [[pdfViewOutlet1 view] setNeedsDisplay:YES]; for both the views.
FirstView *FirstViewController = [[FirstView alloc] initWithNibName:kFirstView bundle:nil];
[FirstViewController setPdfDoc:pdfDoc];
[FirstViewController setPageCnt:pageCnt];
self.myCurrentViewController = FirstViewController;
[[_myCurrentViewController view] setNeedsDisplay:YES];
[transition setSubtype:kCATransitionFromLeft];
[[_myTargetView animator] addSubview: [_myCurrentViewController view]];
and in the awakeFromNib: method of first view I have:
if(pdfDoc==nil )
return;
[pdfViewOutlet1 setDisplayMode: kPDFDisplaySinglePageContinuous]; //kPDFDisplaySinglePage or kPDFDisplayTwoUp;
[pdfViewOutlet1 setDocument:pdfDoc];
NSRect myRect = { { 0,0 }, { 450, 200 } };
[pdfViewOutlet1 setFrame: myRect];
[pdfViewOutlet1 goToPage: [[pdfViewOutlet1 document] pageAtIndex: pageCnt]];
[pdfDoc release];
[[pdfViewOutlet1 view] setNeedsDisplay:YES];
How can I see the pdf pages without resizing the views using mouse?
the issue is solved, i was using setWantsLayer on my Parent view which was creating the issue.
I am using IKImageFlowView in my application and need to add a nsbutton over it,
I am using the code as given below,
In my .h file
IBOutlet id browserView;
in nib added a custom view and changed its class as myImageFlowView as I am subclassing from IKImageFlowView as
#interface myImageFlowView : IKImageFlowView
and in my appController class I am trying to add button to browserView with following code snippet,
NSRect initialFrame = NSMakeRect(20.0, 50.0, 100.0, 100.0);
NSButton *myBtn = [[NSButton alloc] init];
[myBtn setFrame:initialFrame];
[myBtn setBordered:NO];
[myBtn setAutoresizesSubviews:TRUE];
[myBtn.cell setImageScaling:NSImageScaleAxesIndependently];
[myBtn setImage:[NSImage imageNamed:#"AppleColor.png"]];
[browserView addSubview:myBtn];
I am not able to add this button as a subview to IKImageFlowView,I can add button to NSView.
What I am doing wrong.Please help.