iOS Refresh Control Height - ios

How can I set the height of the refresh control. I am using http://www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/
to create a custom loading icon for refresh control. I want to increase the height of the refresh control ie the space between navigationbar end and where tableview begins so that I have space below and above the image. Below is the code I use :
- (void)setupRefreshControl
{
// Programmatically inserting a UIRefreshControl
self.refreshControl = [[UIRefreshControl alloc] init];
// Setup the loading view, which will hold the moving graphics
self.refreshLoadingView = [[UIView alloc] initWithFrame:self.refreshControl.bounds];
self.refreshLoadingView.backgroundColor = [UIColor clearColor];
// Setup the color view, which will display the rainbowed background
self.refreshColorView = [[UIView alloc] initWithFrame:self.refreshControl.bounds];
self.refreshColorView.backgroundColor = [UIColor clearColor];
self.refreshColorView.alpha = 0.30;
// Create the graphic image views
self.compass_background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"compass_background.png"]];
self.compass_spinner = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"compass_spinner.png"]];
// Add the graphics to the loading view
[self.refreshLoadingView addSubview:self.compass_background];
[self.refreshLoadingView addSubview:self.compass_spinner];
// Clip so the graphics don't stick out
self.refreshLoadingView.clipsToBounds = YES;
// Hide the original spinner icon
self.refreshControl.tintColor = [UIColor clearColor];
// Add the loading and colors views to our refresh control
[self.refreshControl addSubview:self.refreshColorView];
[self.refreshControl addSubview:self.refreshLoadingView];
// Initalize flags
self.isRefreshIconsOverlap = NO;
self.isRefreshAnimating = NO;
// When activated, invoke our refresh function
[self.refreshControl addTarget:self action:#selector(refresh:) forControlEvents:UIControlEventValueChanged];
}
I have tried using
self.refreshControl = [[UIRefreshControl alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
But that does not seem to work.

From the UIRefreshControl Class Reference:
The UITableViewController object that owns a refresh control is also responsible for setting that control’s frame rectangle. Thus, you do not need to manage the size or position of a refresh control directly in your view hierarchy.
You could try some hacks like swizzling UITableViewController methods or adding layout constraints, but they're probably not worth it.
Instead, I'd use a custom library like CBStoreHouseRefreshControl to accomplish what you want.

Sounds like you're looking for more space inside of the refresh control. To change the spacing in the way you mention, you can either change the coordinates of the UI elements (compass + spinner, in my example) or add padding to your images.
The scrollViewDidScroll method is where I set the UI coordinates. That method is called as the table is pulled down, and the further it is pulled, the more the elements are moved.
Lines 55 and 56 in JRTableViewController.m are where the updated frames are applied to the elements (and UI actually moves). If you need more space inside the refresh control, you can change the positioning of the elements by changing the frame.
I hope that answers your question, if not, let me know more about what effects you're looking to achieve. And hope our article has been helpful! Let us know what you create =)
--Anthony

UIRefreshControl sizes itself to fit it's subviews. So you need to change their size to get the control itself to change size.
In your UIRefreshControl subclass you can do something like:
override func layoutSubviews() {
for view in subviews {
view.frame = CGRectMake(1, 2, 3, 4) // or whatever size you want
}
super.layoutSubviews()
}

Maybe a hack. You can remove all views and place them agian

Related

Create an invisible view that is interactable in swift

For prototyping I am looking to create a invisible interaction area.
If I set the alpha to 0, you can't interact withit.
If you set it to
hidden, it also does not receive gesture events.
Why do you want to use a View for this, Instead you could just use a UIButton and set frame to your current view's frame & set its background color to clearColor like below,
self.invisibleButton.backgroundColor = [UIColor clearColor];
This will do the same action & reduce little works like adding Tap gesture and setting some properties for the view if you go with View.
The best solution I have found is to set the background color to an invisible color. You can't see the button but you can interact with it.
In the init I put:
self.backgroundColor = UIColor.blueColor().colorWithAlphaComponent(0)
Is there any better way to do this?
Create a UIView enable userInteraction and make clear background color
UIView *viewsample=[[UIView alloc]init];
viewsample.frame= CGRectMake(0, 0, 200, 200);
viewsample.backgroundColor= [UIColor clearColor];
viewsample.userInteractionEnabled=YES;
[self.view addSubview:viewsample];
UITapGestureRecognizer *tapSkip = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(iviewsampleClicked:)];
[viewsample addGestureRecognizer:tapSkip];
method called when it touched
-(void)iviewsampleClicked:(UIGestureRecognizer*)gesture{
}

How to keep the UI-Searchbar visible when user slide upward in tableview

In my app when the user slide down the UI-searchbar become disappear, which I want but when the user slide up I want UI-Search bar become visible at once.
I want to have code that tell me when the user had slide upward in tableview cell and enable the uisearch-bar.
You can use tableHeaderView for this type of work.
In your viewDidLoad write below code.
- (void)viewDidLoad
{
**// Take one view and subview that view in the tableview.**
UIView *viewsearch=[[UIView alloc]initWithFrame:CGRectMake(0,-10, 320,83)];
[self.Yourtablename addSubview:viewsearch];
**//Now take any controls which you want to show in your header. e.x label,button,searchbar**
UILabel *lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,5,100,20)];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.textColor=[UIColor whiteColor];
lbl1.userInteractionEnabled=YES;
[viewsearch addSubview:lbl1];
lbl1.text= #"BUY THE NEW APPLE TV FROM THE APPSTORE";
**//Here is the code.With the help of this code when you scroll UP the headerview hide.**
self.Yourtablename.tableHeaderView = viewsearch;
self.Yourtablename.contentOffset = CGPointMake(0, CGRectGetHeight(viewsearch.frame));
}
May be it will help you.

ios uitableview bounce went wrong

I implemented a horizontal table view and it looks like this
The category bar, Dining Shopping something, is a horizontal table view and here is the implementation code.
LogInfo(#"Show Category Table start");
// add categories to be subview controller
self.categoriesTable = [[UITableView alloc] init];
self.categoriesTable.transform = CGAffineTransformMakeRotation(-M_PI * 0.5);
[self.categoriesTable setFrame:CGRectMake(0, 64, SCREENWIDTH, 44)];
self.categoriesTable.showsVerticalScrollIndicator = NO;
self.categoriesTable.showsHorizontalScrollIndicator = NO;
self.categoriesTable.pagingEnabled = YES;
self.categoriesTable.delegate = self;
self.categoriesTable.dataSource = self;
self.categoriesTable.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.superView addSubview:self.categoriesTable];
LogInfo(#"Show Category Table Finished");
self.categoriesTable.backgroundColor= [UIColor redColor];
It works as expect but if I change view, for example, I click any button to go to other view and go back to this view. The tableview looks like this
This problem also happpens even if I disable the bounce effect of the table view. Does anyone know how to solve this problem? Thanks!
Rather than applying a transform to the table to make it horizontal, use a collectionView with a horizontal layout.
Edit: If you want to continue using your current setup, try disabling automaticallyAdjustsScrollViewInsets on your view controller.
self.automaticallyAdjustsScrollViewInsets = NO
Edit 2: If you're curious, since iOS 7 every view controller looks at its topmost/first scroll view and adjusts its contentInsets to compensate for the navigation bar transparency which is enabled by default. In this case of course, such behaviour isn't desired at all.

Adding updating elements such as a level number and coin total to a navigation bar?

I have managed to change the navigation bar to a custom stretch image and turn the back button a different colour. I'm having trouble setting a level number and coin total in the navigation bar.
I figure there has to be any easier way then messing about with progress HUD's and such - which is all I have seen mention from my research.
I'm trying to achieve a similar look to that attached below - element wise not graphically.
Thank you for any help in advance.
Two solutions:
Make the entire navigation bar into a custom view with your own elements, then update them as needed. Do this using the titleView property of UINavigationItem.
Use the leftBarButtonItem, titleView, and rightBarButtonItem with your own custom views.
I prefer the second method because it is more scalable (visually) - that is your view controller will layout correctly in landscape mode, or on an iPad, or in an oddly sized popover, etc. The left item will align to the left, the right to the right and the middle one in the middle. However, it's a bit more complicated because the left and right items need to be of type UIBarButtonItem. We can get around that like this:
// Set up the red star thing in the middle with a number 6 on it
MyRedStarView* redStarView = [MyRedStarView redStarViewWithValue:6];
self.navigationItem.titleView = redStarView;
// Set up the 'word' button on the left
MyWordButton* wordButton = [MyWordButton defaultWordButton];
UIView* buttonHolderView = [[UIView alloc] initWithFrame:CGRectZero];
buttonHolderView.backgroundColor = [UIColor clearColor];
[buttonHolderView addSubview:wordButton];
buttonHolderView.frame = wordButton.frame;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonHolderView];
// Set up the coin indicator on the right
MyCoinView* coinView = [MyCoinView coinViewWithValue:515];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:coinView];
Notice how I wrapped the button (on the leftBarButtonItem) in a holder view - this is only necessary if you want to do some kind of view transitions on the button. For example if it changes in different contexts and you want to animate the transition by removing the button from the holder view and adding a different one (with a view transition). On the right bar button item I didn't do this, just to show the different approaches.
Of course I used some fake view types to demonstrate - you'd actually have your own references to these so that you can set the property values and update the display of the numbers.
try the following code assuming you already have the navigationView in place
- (void)viewDidLoad
{
// Custom Navigation Bar
// -----------------------------------
UIView *navigationCustomTitle = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 20.0)];
navigationCustomTitle.backgroundColor = [UIColor clearColor];
UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"icon.png"]];
UILabel *titleCustomLabel = [[UILabel alloc] initWithFrame:CGRectMake(30.0, 0.0, 260.0, 20.0)];
titleCustomLabel.text = #"A nice title";
titleCustomLabel.textColor = [UIColor whiteColor];
titleCustomLabel.backgroundColor = [UIColor clearColor];
titleCustomLabel.font = [UIFont fontWithName:#"HelveticaNeue-CondensedBold" size:(16.0)];
[navigationCustomTitle addSubview:titleCustomLabel];
[navigationCustomTitle addSubview:icon];
self.navigationItem.titleView = navigationCustomTitle;
}

Handling view resizing programatically heights, widths and margins

I am trying to setup a view programatically. Through preference I prefer to programme the views as opposed to using Interface Builder, I feel I have a better control for some reason...
I am setting up a view with two subviews and a button. What I am trying to acheive is the same view when the orientation changes. Initially I thought I needed to calculate the screen size then calculate some divisions to work out the changes, but it appears I can handle on UIViewAutoresizing***
The issue I experience is with the top margin. Here is my code for the subviews.
// Create sub view for Logo
UIView *logoView =[[UIView alloc] initWithFrame:CGRectMake(0,0,320,280)];
[logoView setBackgroundColor:[UIColor blueColor]];
logoView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
// Create sub view
UIView *buttonView =[[UIView alloc] initWithFrame:CGRectMake(0, logoView.bounds.size.height, 320,200)];
[buttonView setBackgroundColor:[UIColor redColor]];
buttonView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin;
Here is a picture of portrait and landscape where you can see the issue, with the 'white' space.
You either want the two views (red and blue) to end up with a proportionate amount of space after the rotation:
logoView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin;
buttonView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin;
Or you want the red view to end up the same size as it started out, and the blue view to adjust to make room for it:
logoView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
buttonView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;
use autolayouts . U dont have to deal with any of these issues ...

Resources