ringa_lee2017-04-17 16:35:41
Swift:
let leftBtn = UIButton(type: UIButtonType.Custom)
leftBtn.frame = CGRectMake(0, 0, 65, 35)
leftBtn.setImage(UIImage(named: "icon_xm_homepage_downArrow"), forState: UIControlState.Normal)
leftBtn.adjustsImageWhenHighlighted = false
// leftBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Normal) //设置按钮字体颜色
leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center
leftBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -50, 0, 0)
leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 45, 0, 0)
leftBtn.setTitle("天津", forState: UIControlState.Normal)
leftBtn.addTarget(self, action: "showLeft", forControlEvents: UIControlEvents.TouchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: leftBtn)
PHP中文网2017-04-17 16:35:41
类似的这种小图标,一般有一下几种方式:
使用css sprites设置background-position来设置这种小图片
使用图标库,比较流行的有阿里巴巴矢量图形库或者bootstrap字体图标
可以自己用css写一个caret-down类就行
美团这个应该是使用css sprites,这个相对比较流行,兼容性比较好消耗资源也相对较低