iPhone: UITableview background image stretch/pull/scroll up beyond the view bounds - ios

I have a very specific requirement to fulfil.
Lets say this is my original background image (on the right).
This is how my image should be on the screen by default.
And this is how it should be when I do a "pull down" gesture on the UITableView.
I want to set an image (shown above) as a view's background. A UITableView to be specific.
NOTE: Image size is more than the view size.
When I try to pull down the view beyond the bounds of the view, the image should continue to show up and should not break. With the current implementation the image from the bottom part shows up.
Any ideas how I can achieve this? Pardon me if the solution is obvious.

You can do this by only one line of code
[yourView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"YourBGImgName.png"]]];
OR Alternately
put one UIScrollView and set it's background color with above way and you can find your background repeating when you scrolling your scrollView.

Set the top part as the background for a UITableViewHeaderFooterView in the header and do the same for the footer. Then set a negative inset for your tableView.
Something like
[self.tableView setContentInset:(UIEdgeInsets){-headerHeight, 0, -footerHeight, 0}];

Related

How to draw a progress indicator on the background of a cell in iOS 9?

I would like to draw rectangles in the background of the cells of a table view, whose size will indicate the progression of subsequent tasks:
The progression bar should take the whole height of the cell and its width will be programmatically set when the TableView is shown.
I would like to know how to get this result with a simple and efficient approach. I have not been able to find good practices for drawing a custom background for UITableViewCells, using CALayer or another solution.
Also, I would appreciate if the technical solution for this task could also be valid when deciding to animate the progression of the bars.
Thank you.
Simple solution without calculation is that, prepare a set of static different background images, and set them depend on the progress value.
Other solution requires you to create Progress view programmatically in table view's cellForRowAtIndex method and add to cell.contentView as subview
UIProgressView *progressView = [[UIProgressView alloc] init];
[progressView setFrame:cell.frame];
[cell.contentView insertSubview:progressView atIndex:0];
You can make progressview alpha property to 0.5 or some other value in order for your top views in cell.contentView to be visible properly

xcode iOS increase UIButton hit area

I am attempting to increase the hit area of my UIButton. I have a new Xcode project with a UIButton in the center of the storyboard. The button is connected to my view controller with an outlet and action. I'm programmatically able to change the button title and just for fun made it's action change the background of the view when I tap the button. So I know everything is connected and works.
From what I've read online, this should work but it's not.
[button setFrame: CGRectMake(button.frame.origin.x, button.frame.origin.y, -64, -64)];
Any thoughts? I've tried without the negative margins and that doesn't work either. BTW, I have tried the many places this question is asked but it's not working. Thank you for your help. Also, I've heard subclassing UIButton could create an issue, any thoughts on that?
Update:
The UIButton I want to make has a background color and is a specific size. I want to keep that size the same but increase the hit area around it without distorting the look of the button.
i think you just want to use the same button for restricting the background color or back ground image to the same area and increase the touch area?
as per my knowledge you cannot do that in interface builder. But thru coding you can by using layers.
take outlet of the button
CALayer *buttonlayer=[CALayer layer];
buttonlayer.frame=CGRectMake(50 , 50, 50, 50); // set the frame where you want to see the background color or background image to be visible in your button
buttonlayer.backgroundColor=[[UIColor colorWithPatternImage:[UIImage imageNamed:#"yourimage.png"] ] CGColor]; // if u want image (but remember the image size must same as your layer frame it may look bad if the image bounds does not mach your layer bounds, because you are setting color not image)
// to set color (donot use if you want image, use colorWithPatternImage to set image color)
buttonlayer.backgroundColor=[[UIColor graycolor] CGColor]; // if you want only color
// you can add round rects to the button layer
buttonlayer.cornerRadius=2.5f;
[yourbutton.layer addSublayer:buttonlayer];
i am not sure what you are looking for i hope this help you but check the image once
To increase the hit area without distorting the background color or image, it would probably be easiest just to separate them. Have a clear UIButton, with no background color, above a UIView (or UIImage, etc) that provides the visuals. That way, you can do whatever you want to the frame of the UIButton, and it won't affect the visuals unless you apply the same transformations to the other UIView.
As for why that line of code doesn't work, the third and fourth elements in CGRectMake aren't margins, they're dimensions: you can't have a negative height and width. Put in the ultimate size you want it to be, not the change or the margins, (i.e. if you want to shrink a width of 100 by 20, input 80).
Subclass UIButton and implement the backgroundRectForBounds method.
Expand the frame to your desired touch area size, then shrink the bounds of the background by adding insets.
- (CGRect)backgroundRectForBounds:(CGRect)bounds {
return CGRectInset(bounds, -50, -50);
}
More info here:
https://developer.apple.com/library/ios/documentation/uikit/reference/uibutton_class/index.html#//apple_ref/occ/instm/UIButton/backgroundRectForBounds:

Scroll the UICollectionView Background With The UICollectionView

I am building an app that is presenting articles from a blog. I am using UICollectionView to present images that are parsed from the blog for each of the cells. This is my first go-round with a UICollectionView so I am wondering how you set up a background image of something like shelves that will scroll with the UICollectionView?
I have tried using:
self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"shelves.jpg"]];
But this doesn't do anything.
What you're trying:
self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"shelves.jpg"]];
should work. I do exactly this in viewDidLoad and it works for me. I would check that you're getting a valid image. Perhaps "shelves.jpg" needs to be added to the project?
You can just set the size of a UIImageView for your background to a size that is larger than the current UIView size then change the origin (increment) of that UIImageView based on your current visible cells for your UICollectionView. This would give you a side scrolling (parallax) effect based on which cells are currently being viewed.
There are other parallax effects people have created that you can get creative with to apply to your scenario. The idea is pretty simple.

UITextView won't scroll from outside particular area

I have a UITextView with approx 100 lines(for testing purpose its static) which scrolls fine but when i try to scroll from approx 150 its from the bottom i can not scroll. That means it lets me scroll from only certain area of the textview. for example see the image below. If i try to select and scroll above 3 line from top, i can scroll but below 3rd line, It won't let me scroll. I went through documentation but couldn't find anything that makes sense.
Try resizing the frame of your UITextView so it does not overlap the UITabBarView. If you create this in interface builder, you can resize it there.
if there is some area that is not taking ui touches, thAT means, your UITextView is being overlapped by another view. try:
[self.view bringSubviewToFront:textView];
also think about Enrico's answer.
Put Background color for TextView. It will give you extact idea of TextView Complete framing and is it sub view of background or foreground.

iOS: How do I put an image on top of the tableView like iBook

If you scroll all the way up on the iBook, you can see an apple mark (above search and two buttons). How can you put such image on top of the TableView?
My first guess is that apple just used an image as its background and somehow aligned it right. Am I on right track?
It's a UIImageView, either set as a tableHeaderView (check the docs) with the table given negative-top contentInset, or just added as a subview of the table view itself. The latter's probably simpler—just set the image view's position to something with a negative Y value.

Resources