swift + jj实践
1,UIButton里面的字体和图片左对齐
button.imageEdgeInsets = UIEdgeInsetsMake(0,180/2,0.0,320/2)
let btnRect = button.titleRectForContentRect(button.bounds)
let width = button.frame.size.width - 180/2 - image!.size.width*4
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, width - 10 - btnRect.size.width);
2, 将两个Label 转换成一个:
原:
viewY = viewY + 100/2
viewHeight = 60/2
var friendInviteLabel = UILabel()
friendInviteLabel.frame = CGRectMake(viewX,viewY, viewWidth,viewHeight)
friendInviteLabel.backgroundColor = UIColor.clearColor()
friendInviteLabel.textAlignment = NSTextAlignment.Center
friendInviteLabel.font = UIFont.systemFontOfSize(38/2)
friendInviteLabel.textColor = DefaultTabBarColor
friendInviteLabel.text = Str_label_invite_friends
self.addSubview(friendInviteLabel)
viewY = viewY + viewHeight
viewHeight = 48/2
var friendInviteBonusLabel = UILabel()
friendInviteBonusLabel.frame=CGRectMake(viewX,viewY, viewWidth,viewHeight)
friendInviteBonusLabel.backgroundColor = UIColor.clearColor()
friendInviteBonusLabel.textAlignment = NSTextAlignment.Center
friendInviteBonusLabel.font = UIFont.systemFontOfSize(26/2)
friendInviteBonusLabel.textColor = COLORWITHRGB(11,179,125)
friendInviteBonusLabel.text = Str_label_invite_bonus
self.addSubview(friendInviteBonusLabel)
之后 :
viewY = viewY + 60/2
viewHeight = 60/2 + 48/2
var friendInviteLabel = UILabel()
friendInviteLabel.frame = CGRectMake(viewX,viewY, viewWidth,viewHeight)
var strlength = Str_label_invite_friends.length
var bounsStrLength = Str_label_invite_bonus.length
// let str = Str_label_invite_friends + "\n" + Str_label_invite_bonus
var inviteStr:NSMutableAttributedString = NSMutableAttributedString(string:Str_label_invite_friends, attributes:[NSForegroundColorAttributeName:DefaultTabBarColor,NSFontAttributeName:UIFont.systemFontOfSize(38/2)])
inviteStr.addAttribute(NSForegroundColorAttributeName, value: UIColor(red: 11.0/255, green: 179.0/255, blue: 125.0/255, alpha: 1.0) , range: NSMakeRange( strlength - bounsStrLength , bounsStrLength))
inviteStr.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(28/2), range: NSMakeRange(strlength - bounsStrLength ,bounsStrLength))
friendInviteLabel.attributedText = inviteStr
friendInviteLabel.backgroundColor = UIColor.clearColor()
friendInviteLabel.textAlignment = NSTextAlignment.Center
friendInviteLabel.numberOfLines = 0
self.addSubview(friendInviteLabel)
3, navigationBar 添加背景
var imageView:UIImageView = UIImageView(frame:CGRect(x:0 ,y: -20,width: xWidth,height: CustomNavbarHeight-20))
imageView.image = UIImage(named: "action bar_bg.png")
self.navigationController!.navigationBar.addSubview(imageView)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)