Is there a way to remove the gap under my Today Extension - ios

Ok, I'm trying to make todays view extension and I would really like to make it have 77 pixels of height. But no matter what iOS keeps inserting a padding under my top view.
Like this:
You see, I'm calling setPreferredContentSize passing a height of 77. But the gap is always there. Even If I set my content size smaller, it gets cut, but the padding is still there and apparently with the same size, the image bellow illustrates:
Does someone have anything to say about this? I'm trying this because Evernote's widget seems to manage to remove that gap, but i'm really stuck, I even disabled autolayout, but nothing.

Try adding the following:
-(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets {
return UIEdgeInsetsMake(
defaultMarginInsets.top,
defaultMarginInsets.left,
0,
defaultMarginInsets.right );
}

Related

UICollectionViewCell spacing to fill maximum area

First time using a UICollectionView if you can believe it, and I'm wondering how to get the cells to basically fill out the maximum allowed space.
The the view for the SE, it's filling out... mostly OK and how I want it. Sure, I'd like the blocks to go all the way to the bottom of the black area (colors are temporary of course), but it's close enough.
On the iPhone X, and other larger screened phones of course, it maintains the "minimum" spacing, but what I'd like it to do is to auto adjust the spacing so that they fill out the area. Top two blocks at the top and bottom two blocks at the the bottom, with equally distributed space in between.
Oddly enough, I was able to achieve this quite easily when I did it manually with each of them in the regular view. I started trying to use a UICollectionView because it started to really look ugly once it rotated into landscape mode. Here's a shot of how those items were setup using the more manual method.
Any suggestions? Seems like something that'd be an easy switch... but I seem to have hit a wall and am stumped. Am I missing something so blatantly obvious here, or what?!?
Oh, and I've also toyed with using:
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
To set the spacing of the line items programmatically, but that wasn't without problems either. In there, I was checking for the screen height, dividing by the count of items and using a variation of that as the spacing.
That seemed to "work" at first.
But in my testing, that function only fires when the view is very first loaded, and then only when it goes into landscape mode. When it comes out and goes back to portrait, it doesn't re-fire and recalculate. Thus... keeping the (now new) landscape spacing.
You need to create UICollectionViewFlowLayout and compute size of the items programmatically.
Or override UICollectionViewDelegateFlowLayout item size.
https://developer.apple.com/documentation/uikit/uicollectionviewdelegateflowlayout/1617708-collectionview

Best approach to showing or hiding dynamic content in iOS

I've been doing iOS for a while now, but when it comes to dynamically hiding / showing elements, I'm a bit lost.
Coming from Android, I'm used to being able to simply set views to visibility gone, but this doesn't exist on iOS.
So let's say I have the following scenario:
Basically I want to have a table, but the table should not fill the entire view controller. Instead it should leave place for optionally either a button, a multiline label, or possibly both at the bottom (if visible, these should be fixed, not scroll).
One way to solve this would be to use auto layout and modify constraints, like adding a zero height constraint. But that would make iOS kill one of the other constraints, which would make it hard to change it again. For the label, I wouldn't always want to have a height constraint, because it could be multiline, and should take the size it needs.
Maybe it's easier to skip autolayout here and modify frames instead, I don't know.
My question is: What approach would be best here?
Is there some other way of doing this I haven't thought of, or do I have to try to do what I described above?
I'm not primarily looking for code (code can be ok), but I'm more interested in a description of how it can be done.
I'd like to support iOS 7.
This problem had a variety of solutions, and opinion based, but I'm facing such questions a lot, when I don't know what to choose and what would be the "right thing".
So, I my opinion, the best solution here is using autolayout, you need to set height of label manually, but you have a few methods for this, at least you can play with it and if you don't succeed ask question about it. Using frames, you'll face same problem of calculating height, right? But with auto layout, you only need to set height, vertical space to 0, when you need to hide message.
You can also use constrains with priority lower 1000, and remove completely constraints from message (button, label) if you don't need it at all anymore.
For example, taking your layout image, you can make UIView with subviews: button, label. Top constraint connect to the UITableView, other constraints to the sides.Label and button will calculate the view's height. The only question here is label height.
So in ios assuming that the background of both these objects is opaque only the front most view in the Heirarchy will be visible and interactable, An easy solution would be to change the different frames of these two things you need and make sure they are in the back of your view heirachy, and when you need them to appear use view.bringSubviewToFront(mySubview) and view.pushSubviewToBack(mySubview) to make it disappear again. View obviously would be referring to main view of your view controller.

Using CGFLOAT_MAX to hide UITableViewCell separator

I am trying to hide the separator for a specific UITableViewCell and am using cell.separatorInset = UIEdgeInsetsMake(0.0, CGFLOAT_MAX, 0.0, 0.0);. This causes very weird problems on older devices and works perfectly on newer devices. On an iPhone 5 for example, it will cause the cell to flicker and be blurry. Changing CGFLOAT_MAX to a fixed number like 5000.0 makes all of the issues disappear. Any idea why this happens?
That approach sounds unwise. You’re probably best off just disabling the table’s default separators and having your cells (minus the one you want it hidden for) draw their own, either in their -drawRect: or by adding a thin view at the top or bottom of each cell.
There’s also the solution described here—setting the horizontal insets to half the width of the cell, so the separator ends up being 0pt in width—but given the history of changes listed in that article you can probably expect that to end up breaking as well.
Running on iOS 9.1, I am seeing a similar issue on iPad.
In my case the screen flickers black whenever it's launched (my cell is on the initial screen); or whenever I use Split View on iPad Air 2; resizing my app causes flickering when my app is rendered.
I have bug reported this to Apple as I think we should be able to use CGFLOAT_MAX instead of a magical high number to achieve the same effect. In fact I've even suggested that perhaps we should have an API to hide the separator; I'm sure many before myself have asked for this though.
rdar://23768136 (I will update here whenever I get any news on it). In the mean time, just use a silly big number that's for sure going to get the separator hidden - something like 5000.

UIScrollView zooming only to the size of UIImageView

I have UIScrollView in which UIImageView is held like on the screenshot:
My problem appears when I zoom and instead of being able to scroll only in the area of my image (subview of scroll view) I'm able to scroll around the original size so I get a lot of white space around my image which isn't what I want. You can see what happens on the screenshot below:
I wonder what should I update to keep my scrolling area only the size of the image?
After some research, some trials and errors I've finally achieved what I was planning to do.
First of all, I wanted to use only autolayout with IB which sure can be done but with some effort. After some digging I've found this technical note which by "Pure Auto Layout Approach" understands adding contraints in code but I was aiming at only IB which led me to this simple but beautiful solution called ios-imagescroll. After investigating this code with joy that I've finally found solution I came with some error but only on iOS 8 devices... iOS 7 worked like charm out of the box.
I assume that due to big changes in iOS 8 autolayout is more strict and you must be 100% sure what you want to accomplish. It turned out that this slight change MATTERS on iOS 8:
Of course, this bug, fix (call it whatever you like) was fixed by experimenting with everything but I guess that UIScrollView's content view (in that case UIImageView) must be the first item in constraint.
[yourScrollView setContentSize:CGSizeMake(yourScrollView.size.width, yourImage.frame.origin.y + yourImage.frame.size.height+35 )]; //let's say just 35 ...
yourImage may have x,y origins like (0,0) [I see a lot of space above it, so I assume you have set other values for x,y]

How can I get the frame positions of subviews in Apple's UITableView styles?

I'm trying to make a cell that looks just like Apple's UITableViewCellStyleSubtitle, except the textLabel is a UITextView (so it can be edited). I just set the textLabel to " " (so that the detailTextView is in the right place) and park a UITextView on top of it. So far, so good. It's working except that I can't quite get my UITextView to line up with the other textLabels of the other cells. I'm a tad off (in more ways than one...).
So that got me wondering: is there a way to get the frame of the various bits of a UITableViewCellStyleSubtitle cell? The obvious (or seemingly-obvious) way does't work. cell.textLabel.frame returns nil, and if you print it, it shows (0, 0, 0, 0) for its frame. Maybe there's another way.
I realize I could hardcode it, but I'm still guessing what those dimensions might be. Programmatically would be nicer... I think.
Thoughts?
Thanks,
Bill
A view's frame isn't valid if the view's transform is not the identity transform. I haven't tried it, but you might be able to duplicate the positions of the elements this way:
store the cell's transform
set the cell's transform to CGAffineTransformIdentity
get the frames of the elements
set your own elements with the same frames
apply the original transform to your cell
It'd be interesting to know if that works -- please post back if you have good luck.

Resources