UIScrollView stops scrolling after adding UILabel on Storyboard - ios

I encountered a strange problem while working with the UIScrollView and UILabel.
My viewDidLoad function looks like this:
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view.
scrollViewContent.contentSize = CGSizeMake(320, 960);
scrollViewContent.scrollEnabled = YES;
}
If I add UILabel on Storyboard scroller stops scrolling.
Also i added label as subview but this does not change anything
[scrollViewContent addSubview:labelHeader];
Does anyone had a similar problem or know a solution?

I've encountered this problem once and solved it with this simple fix:
In storyboard mode first select your UIScrollView and then open the "Resolve Auto Layout Issues"-menu. Click the option: "Add missing constraints".

Related

UIStackView not reversed when viewDidLoad in RTL language

I have a UIStackView in Storyboard with structure as below and want to scroll it to a specific button in viewDidLoad.
This is how I'm scrolling it.
[self.scrollView scrollRectToVisible:button.frame animated:YES];
The problem is, when setting system language to a RTL language (such as Arabic), the direction of UIStackView and button.frame are still left to right in viewDidLoad, so the scroll position is incorrect.
What should I do to fix this?
As you have seen, frame setup is not completed in viewDidLoad.
Move that code to viewDidAppear:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.scrollView scrollRectToVisible:button.frame animated:YES];
}

UITableview covering button

I tried to make floating button on top of uitableview, I already set uitableview to back and the button is in the front on storyboard but when I run the application the table covering the button. How can I make the button to always on front?
Here is the screenshot:
Try to bring your subviews on top of tableview.
- (void)viewDidLoad {
[super viewDidLoad];
[self.view bringSubviewToFront:yourButton];
}
Set autoresizing mask of your buttons from bottom then check. If buttons are not appearing then add this code to in your viewDidLoad method -
[self.view bringSubViewToFront: btn_Cancel];
[self.view bringSubViewToFront: btn_Delete];

UITextView content going under UINavigationBar

I have a UITextView inside a UIViewController that uses auto layout to pin it to 0 on all sides (so it fills the whole screen). I also have this view being pushed using UINavigationController.
I'm running into a weird error where if the UITextView has enough text so that it runs off the screen, then content gets set under the UINavigationBar. If there is not enough text to fill the screen the layout of the text doesn't go under the UINavigationBar.
Here is what's happening, this is when there is enough text that it goes off the screen and you need to scroll to view all of it.
I've tried:
Setting the content inset of the UITextView.
Made sure the UINavigationBar isn't translucent.
Tried setting this self.automaticallyAdjustsScrollViewInsets = NO;
Inside viewDidLoad of viewController where your textView is, add this:
self.edgesForExtendedLayout = UIRectEdgeNone;
I'm not sure why the problem was occurring but this fixed it:
- (void)viewDidLayoutSubviews {
if (self.textView) {
[self.textView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
}
}

Add clickable and fixed subview to UITableViewController?

I'd like to place an ADBannerView object onto my UITableView screen statically, what means that I want it to always stay above my toolbar (self.navigationController.toolbar), even when the user is scrolling the tableview. I've solved this by adding by ADBannerView as a subview to my toolbar and given it negative values for the frames origin:
[self setBannerViewSize];
[self.navigationController.toolbar addSubview:bannerView];
The only problem is: I can't click and open the iAd this way - I can see the banner but nothing happens when I tap on it.
Since I'm also using a refreshControl, the option to use a UIViewController instead of UITableViewController and add a tableView manually wouldn't work for me. Is there any other way I can get my ADBannerView statically showing in my table view controller AND still being tappable?
Thank you in advice!
Yay!! After all I succeeded in solving this (really annoying) problem by myself (and a lot of reading around)!
First, I found this really world-changing post. Basically this post handles with the topic that a UITableViewController uses self.view for its tableView property, so overriding the tableView property (or synthesizing it manually) plus giving self.view a new view (from application) and adding tableView as its subview would make it possible to reach the real superview of tableView.
But this still didn't solve my problem, although I was sure it would, because it all made sense. My bannerView appeared in the right place (and was fixed) but it still didn't do anything when clicked. But there was a second minor thing I didn't know about:
As I read in this post the superview of a subview doesn't only have to be userInteractionEnabled but also have a non-transparent backgroundColor. Because my superviews background color was set to [UIColor clearColor] it all didn't work - but setting its backGroundColor to e.g. blackColor solved the whole problem: the bannerView got finally tappable! :)
So, my code is now looking like this:
#synthesize tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
if (!tableView && [self.view isKindOfClass:[UITableView class]]) {
tableView = (UITableView *)self.view;
}
self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
self.tableView.frame = self.view.bounds;
[self.view addSubview:self.tableView];
[self resizeTableToFitBanner];
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:bannerView];
// some other code
}
BannerViewController in Apple's iAdSuite sample code solves this problem very elegantly:
https://developer.apple.com/library/ios/samplecode/iAdSuite/Introduction/Intro.html
I think you should use a container view, and set things up in IB. You can add a tool bar and ADBannerView to the bottom of the view of your navigation controller's root view controller. Fill the rest of the space with a container view - this will give you an embedded view controller automatically. You should delete this one and then drag in a tableViewController and control drag from the container view to the tableViewController to hook up the embed segue.

Set the starting point of a horizontal UIScrollView

I've tried many different solutions but none of them are working for me..
I have a horizontal scroll view, now it starts at the left, but how can i make it start at the middle?
I'm using this code right now in the Controller:
- (void)viewDidLoad {
[scroller2 setScrollEnabled:YES];
[scroller2 setContentSize:CGSizeMake(1735, 300)];
[super viewDidLoad];
}
and
IBOutlet UIScrollView *scroller2; in the header file.
I'd made the content in interface builder (.xib file), and i'm using Xcode 4.2!
Thanks in advance!
You are looking for the contentOffset property.
[scroller2 setContentOffset:CGPointMake(appropriateXDisplacement, 0)];
I think you need to call scrollRectToVisible:animated:
try this in viewDidLoad or viewDidAppear or sth. similar.
[scroller2 scrollRectToVisible:CGRectMake(1735/2.0, 300/2.0, 1,1) animated:NO]

Resources