ios


LeftBarButtonItem position is not correct


I am trying to add a leftbarbuttonitem like this:
with this code:
let button = UIButton.init(type: .custom)
button.setImage(UIImage.init(named: "WhiteBackButton.png"), for: UIControlState.normal)
button.addTarget(self, action:#selector(self.backButtonSelected), for: UIControlEvents.touchUpInside)
button.frame = CGRect.init(x: 0, y: 0, width: 30, height: 30)
let barButton = UIBarButtonItem.init(customView: button)
self.navigationItem.leftBarButtonItem = barButton
I am using this image:
and it sends up looking pushed over like this:
How do I stop it from pushing too far from the left?
WhiteBackButton.png image most likely has white space around/in front of the arrow.
I suggest also be using:
UIBarButtonItem(image:style:target:action:) instead of UIButton it will simplify your code...
https://developer.apple.com/reference/uikit/uibarbuttonitem/1617163-init
If you are changing the barButtonItems a lot can extend ViewController with the following functions and add them to viewWillAppear:
//should have a left and right of each:
func addRightBarButtonWithImage(_ buttonImage: UIImage) {
let rightButton: UIBarButtonItem = UIBarButtonItem(image: buttonImage, style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.toggleRight))
navigationItem.rightBarButtonItem = rightButton
}
func setNavigationBarItem() {
self.addLeftBarButtonWithImage(UIImage(named: “icon.png”)!)
self.addRightBarButtonWithImage(UIImage(named: “icon.png”)!)
}
Hope this helps! Cheers!
let negativeSpacer:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
negativeSpacer.width = -10
self.navigationItem.leftBarButtonItems = [negativeSpacer, leftBarButton]

Related Links

iOS - UITableview cells with shared surface
Xcode fix memory problems
UIWebview remove padding / margin
How do I not get optional in the output?
Material Select blinking on iOS
How to get the Core data Primary key value in ios Swift? [duplicate]
How to remove only minutes from UIDatePickerMode.DateAndTime
UIButton click causing app freeze/Rapid increase in memory
libobjc.A.dylib objc_msgSend crash occurring with core data usage in background thread
Disabling Dynamic Type in Swift
how to make overlay with activity indicator programatically
performseguewithidentifier works with a delay
Type [TeamModel] has no subscript members
Pdf file in webview not scrolling
Ternary Conditional Operator for nil/not nil
Xamarin / IOS / Azure - No 'id' member found on type

Categories

HOME
ssis
crf
x-editable
servlets
react-navigation
styling
weblogic11g
stripe-payments
sony-camera-api
phpmailer
entity
apache-spark-sql
android-vision
pie-chart
asciidoc
bluej
signature
tapi
oracle-agile-plm
postgresql-9.5
jsqmessagesviewcontroller
api-design
cmusphinx
revitpythonshell
missingmethodexception
robotium
selenium-edgedriver
precision
padding
masstransit
codeceptjs
json-c
breakpoint-sass
panel-data
chai
aem-6
hamcrest
sieve-of-eratosthenes
transpose
jupyter-irkernel
caldroid
eve
plasticscm
jpype
mdanalysis
textangular
botkit
integer-programming
gretl
mobile-browser
appdynamics
oracle-aq
dump
easyhook
omniauth
mysql-error-1050
lapply
gwt-material-design
mysql-notifier
topojson
error-correction
mink
codeigniter-upload
xnamespace
pygments
android-location
mongolab
cucumber-java
push-api
axlsx
spatial-index
abort
size-t
sigkill
swift-array
bit.ly
brooklyn
asf
email-spam
mydbr
hebrew
modalpopupextender
pydatalog
buildout
globbing
hamlc
slimbox
dependency-walker
locomotivejs
google-provisioning-api
browserid
doophp
headless-browser
cocosbuilder
android-actionbar-compat
arden-syntax
c++builder-xe2
stumbleupon
jammit
ssao
nntp
directoryentry
treetop
geneva-framework
iphone-sdk-3.1
clipboard-pictures
fogbugz-on-demand
templatebinding

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App