i want to set sectionHeaderTopPadding below iOS 15, but this property works only in ios 15. How can i set section header padding to zero below iOS 15
i have faced a gap issue that appear between table header view & nav bar. So to fix that, just add a tableHeaderView on viewDidLoad. And remember to make sure the header with a non zero height. please try the below mentioned solution might be helpful for you:
if #available(iOS 15, *) {
tableView.sectionHeaderTopPadding = 0
} else{
tableView.tableHeaderView = .init(frame: .init(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
}
Related
I want to inset the table view separator by 10 points from the current automatic inset so it respects the safe area etc. but when I set it in the storyboard it doesn't work as documented.
Turns out the settings in the storyboard are not being respected.
When I added the settings in code then it worked as expected.
tableView.separatorInsetReference = .fromAutomaticInsets
tableView.separatorInset = .init(top: 0, left: 10, bottom: 0, right: 0)
I want to put scrollViewIndicator just a bit more outside(right) of scrollView. But It doesn't go even if I set self.mainMenuCollectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 10, 0, 0);. It might because of inset works as padding and not going out of bounds of scrollView. It stays in the border.
It works for putting indise(left) of the view.
It would be really helpful if you know how can I achieve that.
N: normal
S: It is possible
W: How I want
You need to setup opposite side with minus sign like:
self.mainMenuCollectionView.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: -10)
Don't forget disable clipsToBounds for getting visible subviews outside:
self.mainMenuCollectionView.clipsToBounds = false
I am adding a calendar to my app and thought it would be cool to mimic the format of standard iOS Calendar app as per weekday labels:
In the Calendar app, these labels (S,M,T,W,T,F,S) seem to be integrated into the navigation bar, so I was wondering if there is a way to implement this or if this is something Apple left to themselves (as there seems to be no standard way to add anything but bar button items). Mind you, these labels should be dynamic - e.g. rearrange in case of day 2 as firstWeekDay for certain Locale.
Apple proposes not to resize navigationBar itself, but remove shadow from bar and add custom view under your navigationBar.
Please refer the apple recommended approach for extended navigation bars here - https://developer.apple.com/library/content/samplecode/NavBar/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007418-Intro-DontLinkElementID_2
And your particular scenario - https://developer.apple.com/library/content/samplecode/NavBar/Listings/NavBar_ExtendedNavBar_ExtendedNavBarViewController_swift.html#//apple_ref/doc/uid/DTS40007418-NavBar_ExtendedNavBar_ExtendedNavBarViewController_swift-DontLinkElementID_13
You just need to set a view to your title view of navigationItem for example:
sampleLabel.textAlignment = .center
sampleLabel.textColor = UIColor.white
sampleLabel.font = UIFont.systemFont(ofSize: 12, weight: .medium)
sampleLabel.frame = CGRect(x: 0, y: 0, width: 40, height: 30)
sampleLabel.text = "T"
let titleView = UIView
titleView.frame = CGRect(x: 0, y: 0, width: 200, height: 50)
titleView.addSubview(sampleLabel)
navigationItem.titleView = titleView
You can add labels to your navigationBar like sampleLabel wherever you want.
I am attempting to create margins in my text field so that when I go to type, the text isn't pressed so tightly against the edge.
I tried using this code (above viewDidLoad)
var insets = UIEdgeInsetsMake(10, 10, 10, 10)
Then putting this in my viewDidLoad()
textField.layoutMargins = insets
I ran the program and it still looked like there were no margins. How do I implement margins in a text field in Swift?
Subclass UITextField and implement textRectForBounds:. The simplest strategy is to call super, get the resulting rect, inset it as desired, and return it.
Here's an example result; note that the start and end of the text have considerable white space at the margin (of course the exact amount is up to you):
By creating new UIView with the right(your) values, you can set the padding in UITextField
textField.leftView = UIView(frame: CGRect(x: 30, y: 30, width: 100, height: 100))
textField.leftViewMode = UITextFieldViewMode.Always
There are many great examples on SO to remove the left padding of a UITextView.
How to lose margin/padding in UITextView?
However, I need to remove the right padding too.
I have tried...
[tv setContentInset: UIEdgeInsetsMake(-4,-8,-8,-X)];//where X is any integer
and just about every other permutation of the last two values to remove the padding and nothing seems to work. Have also tried
[tv sizeToFit];
[tv setTextAlignment:[NSTextAlignmentRight]];
The following Text in the Textview says "00"
Although it is iOS 7 only, an extremely clean solution is to set the textView's textContainerInsets as such:
[textView setTextContainerInset:UIEdgeInsetsZero];
textView.textContainer.lineFragmentPadding = 0; // to remove left padding
This will effectively remove all padding (insets) around the text inside the text view. If your deployment target is iOS 7+ then this is the best solution thus far.
To completely remove all padding, the lineFragmentPadding must be taken into account.
let padding = textView.textContainer.lineFragmentPadding
textView.textContainerInset = UIEdgeInsets(top: 0, left: -padding, bottom: 0, right: -padding)
The lineFragmentPadding default value is 5, and is at the beginning and end of fragment rectangle.
Some answers suggested setting lineFragmentPadding to 0. However, as per discussed in the doc, it is not designed to express text margins. So do not set it to 0.
Swift 4 version for the OA
self.tDescription.textContainerInset = UIEdgeInsets.zero
self.tDescription.textContainer.lineFragmentPadding = 0
For iOS 11.7
Following code worked for me:
textView.textContainer.lineFragmentPadding = CGFloat(0.0)
textView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
textView.contentInset = UIEdgeInsets(top: 0,left: 0,bottom: 0,right: 0)
From the Official Documentation:
textContainerInset
: It is possible to set the text container and view sizes and resizing behavior so that the inset cannot be maintained exactly, although the text system tries to maintain the inset wherever possible.
In any case, the textContainerOrigin and size of the text container are authoritative as to the location of the text container within the view.
The text itself can have an additional inset, inside the text container, specified by the lineFragmentPadding method of NSTextContainer.
Please try sub-classing the UITextView and overriding the following method:
- (id)styleString
{
return [[super styleString] stringByAppendingString:#"; line-height: 1.6em;margin-right: 30px; margin-left: 0px; margin-top: 0px;"];
}
Apparently; you can tweak the margin-left, margin-top & whatever you want ;)
My problem is solved this way
if([Utils isiOS7orHigher]){
commentView.textContainerInset = UIEdgeInsetsZero;
}else {
commentView.contentInset = UIEdgeInsetsMake(-11,-8,0,0);
}
for more see http://foobarpig.com/iphone/get-rid-of-uitextview-padding.html