I'm looking to have my textView in Xcode to start at the top because it is currently starting a little under the top.
//This is the code I'm using currently to try and have it start at the top
self.productDescription .scrollRangeToVisible(NSMakeRange(0, 0))
However this is not working. Anyone have any ideas what the problem could be?
The UITextView element has contentInsets by default. You can try changing the values of the textView.contentInset like so:
textView.contentInset = UIEdgeInsetsMake(-4,-8,0,0);
Related
I'm trying to place a table view inside of a basic view controller without any padding on the top and nothing I've tried has worked, no matter what I do there is a gap up top. I placed the following code in my viewDidLoad() for the view controller:
if #available(iOS 11, *) {
tableView.contentInsetAdjustmentBehavior = .never
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
I've gone into storyboard and disabled those settings as well manually:
I do have custom cells I'm not sure if that matters, I do add insetting to the cells but even when I remove that code I have that gap.
Here's the code I customized for my cells:
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = UIEdgeInsetsInsetRect(contentView.frame, UIEdgeInsetsMake(cellSpacingHeight, 0, 0, 0))
}
I've spent a couple hours googling around and I can't figure it out. I'm using the latest swift and Xcode to build this. I even tried to print the values for the tableView's content inset and it came up as all 0s. Does anyone know why I still have the offset or inset up top in my table view?
Wow okay so I finally figured it out, I had set the table view style to Grouped at some point instead of Plain. Once I made it plain, everything worked, I hope this might help someone else in this position!
I have a VC that has a UITableView all over the screen, except the first 66px from the top. There, I have a custom UIView I call "Toolbar" which contains a title and a button.
It looks like this:
I'm trying to add a shadow to the "Toolbar" that will be visible on top of the UITableView. I'm adding it like this:
For some reason, I don't see any shadow when I run the app.
What am I doing wrong? Does anybody know?
Thank you!
Shadow needs some spaces to be shown, you have to add some vertical spaces between your top view(toolbar) and the Table view.
for having a result like the following:
you need to add some space:
ans I also use the following code for adding the shadow:
toolbar.layer.shadowColor = UIColor.black.cgColor
toolbar.layer.shadowOpacity = 1
toolbar.layer.shadowOffset = CGSize.zero
toolbar.layer.shadowRadius = 10
toolbar.layer.masksToBounds = false
I'm using default UITableViewCell and just set icon, label, detailLabel but for some reason with specific text length my icon jumps to the left top corner.
The issue is resolved after switching tab to another one and back.
Here is how it looks:
How it should look like:
It's related to text size and word-wrapping somehow because when I add or remove at least symbol - it works fine.
P.S. I've tried to tableView.reloadData on viewDidLoad, viewWillAppear etc and it doesn't help unfortunately.
UITableViewCell is default, no custom xib / storyboard.
Any ideas what's going on here?
Thanks!
Use auto-layout. Add constraints to icon and labels just.
Got it solved finally.
I was adding left green line like that:
let cellHeight = self.estimatedHeight(todo: todo)
let goalColorView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 3, height: cellHeight))
cell.contentView.addSubview(goalColorView)
goalColorView.backgroundColor = todo.area.uiColor()
and just changed it to
cell.addSubview(goalColorView)
and now it works perfect.
Not sure why.. looks like contentView is just little bit tricky.
Thanks for all your suggestions!
Background
I am creating an application, and inside of its storyboard I have a UIButton element. I need the text of this UIButton to auto-shrink, since it scales based on the size of the view. In storyboard, it has the following properties:
Inside of my code, it says:
guard button.titleLabel != nil else {
throw AutoshrinkError.noTitleLabel(button: button)
}
button.titleLabel!.adjustsFontSizeToFitWidth = true
button.titleLabel!.numberOfLines = 0
button.titleLabel!.lineBreakMode = NSLineBreakMode.byTruncatingTail
button.titleLabel!.baselineAdjustment = UIBaselineAdjustment.alignBaselines
I know that the guard statement passes (i.e. the code below it gets run).
The Problem
The problem is that with the above setup, my button ends up looking like this:
With a newline before the text.
I have tried editing my code in many ways, including setting button.titleLabel!.numberOfLines to 1, setting button.titleLabel!.lineBreakMode to NSLineBreakMode.byClipping, or removing the line about button.titleLabel!.baselineAdjustment. None of these changes have helped the situation. Instead they wind up causing more problems, such as the text not shrinking at all.
If anybody knows how to prevent this newline-scenario from happening, I would appreciate an answer.
Thanks in advance!
Edit 1
The constraints of the UIButton are:
woodgrain is a UIImageView that is used as a background image.
I figured it out! All I had to do was add this one simple line:
button.titleLabel!.baselineAdjustment = UIBaselineAdjustment.alignCenters
I got the idea to adjust the baselineAdjustment from this answer by #rintaro.
Now my UIButton looks like this:
I am currently trying to develop my own iOS-App Extension for the Notification-Center but there is a problem with the width. I can not change my widget to be full width like the Calender-Extension on the screenshot. There is always some space to the left that cuts of my Viewcontroller content. (See the Number Widget at the second Screenshot) It seems this is the default behaviour, but there must be a way around this. Any Ideas how to solve this Issue ?
You have to do this:
- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets{
return UIEdgeInsetsMake(0, 0, 0, 0);
}
Taken from Today Extension Not Positioned Correctly
In your main extension view controller, override - (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets and return whatever UIEdgeInsets your extension needs. If you want 0 padding on all sides, simply return UIEdgeInsetsZero.