Object-c 修改placeholder 文字颜色

本文对比了iOS开发中旧版直接设置UITextField placeholder颜色的方法,转向使用Objective-C运行时动态获取并修改`_placeholderLabel`的文本颜色,提升代码灵活性和维护性。

以前:

[self.nameTextField setValue:UIColorFromRGB(0x666666) forKeyPath:@"_placeholderLabel.textColor"];

新版:

#import <objc/runtime.h>
    Ivar ivar =  class_getInstanceVariable([UITextField class], "_placeholderLabel");
    UILabel *placeholderLabel = object_getIvar(self.searchTF, ivar);
    placeholderLabel.textColor = UIColorFromRGB(0x666666);

 

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>健康食谱</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; background-color: #f8f8f8; color: #333; line-height: 1.6; } /* === 头部搜索栏 === */ .header { display: flex; align-items: center; justify-content: space-between; padding: 13.3333vw 10vw; /* 100 / 750 * 100 = 13.333vw */ background-color: #00bfff; height: 13.3333vw; /* 100px */ position: relative; } .search-bar { flex: 1; display: flex; align-items: center; background-color: white; border-radius: 5.3333vw; /* 40px */ padding: 0 10vw; overflow: hidden; } .search-bar input { flex: 1; border: none; outline: none; font-size: 4.8vw; /* 36px */ color: #666; } .search-icon { width: 8vw; height: 8vw; fill: #ccc; } .scan-btn { width: 10.6667vw; /* 80px */ height: 10.6667vw; background-color: transparent; border: none; margin-left: 10vw; display: flex; align-items: center; justify-content: center; } .scan-icon { width: 6.6667vw; /* 50px */ height: 6.6667vw; fill: white; } /* === 轮播图 === */ .banner { width: 100vw; height: 48vw; /* 360px */ background-color: #eee; margin-top: 10.6667vw; /* 80px */ overflow: hidden; } .banner img { width: 100%; height: 100%; object-fit: cover; } /* === 导航栏 === */ .nav-tabs { display: flex; justify-content: space-around; padding: 13.3333vw 0; background-color: white; border-bottom: 1px solid #eee; } .nav-item { text-align: center; } .nav-icon { width: 13.3333vw; /* 100px */ height: 13.3333vw; fill: #00bfff; } .nav-text { font-size: 4.8vw; /* 36px */ color: #666; margin-top: 5.3333vw; /* 40px */ } /* === 每日推荐 === */ .section-title { font-size: 5.3333vw; /* 40px */ color: #00bfff; margin: 13.3333vw 10vw 5.3333vw; /* 100px, 75px, 40px */ } .recommend-list { display: flex; flex-direction: column; gap: 10.6667vw; /* 80px */ padding: 0 10vw; } .card { display: flex; align-items: center; background-color: white; border-radius: 5.3333vw; /* 40px */ padding: 5.3333vw 0; /* 40px */ box-shadow: 0 2px 4px rgba(0,0,0,0.1); } .card-text { flex: 1; padding-right: 10vw; font-size: 4.8vw; /* 36px */ } .card-img { width: 37.3333vw; /* 280px */ height: 26.6667vw; /* 200px */ border-radius: 5.3333vw; object-fit: cover; } .card-title { font-size: 4.8vw; color: #ff9f43; margin-bottom: 3.2vw; /* 24px */ } /* === 精选食谱 === */ .selected-list { display: flex; flex-direction: column; gap: 10.6667vw; padding: 0 10vw; } /* === 底部 Tab === */ .footer-nav { display: flex; justify-content: space-around; background-color: white; padding: 10.6667vw 0; position: fixed; bottom: 0; left: 0; right: 0; z-index: 999; } .footer-item { text-align: center; } .footer-icon { width: 10.6667vw; /* 80px */ height: 10.6667vw; fill: #666; } .footer-text { font-size: 4.8vw; color: #666; margin-top: 3.2vw; /* 24px */ } .footer-active { color: #00bfff; } </style> </head> <body> <!-- 头部 --> <header class="header"> <div class="search-bar"> <svg class="search-icon" viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5.25 5.25L17.39 18l-5.25-5.25z"/></svg> <input type="text" placeholder="搜索医院" /> </div> <button class="scan-btn"> <svg class="scan-icon" viewBox="0 0 24 24"><path d="M16.5 4.5V2H9.5v2.5H7v10h2.5V15h4v1.5H15v1.5h2v-1.5h2.5v-1.5H20v-4.5h-2.5v-2.5H16.5zm-2.5 2.5h-2v10h2V7zM7 11.5h2.5v-2.5H7v2.5zm10.5-10H9.5v2h4.5V1.5zm0 12h-4.5v2h4.5v-2z"/></svg> </button> </header> <!-- 轮播图 --> <div class="banner"> <img src="https://via.placeholder.com/750x360" alt="医生" /> </div> <!-- 导航栏 --> <div class="nav-tabs"> <div class="nav-item"> <svg class="nav-icon" viewBox="0 0 24 24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg> <div class="nav-text">健康食谱</div> </div> <div class="nav-item"> <svg class="nav-icon" viewBox="0 0 24 24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg> <div class="nav-text">健康检查</div> </div> <div class="nav-item"> <svg class="nav-icon" viewBox="0 0 24 24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg> <div class="nav-text">养生套餐</div> </div> <div class="nav-item"> <svg class="nav-icon" viewBox="0 0 24 24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg> <div class="nav-text">在线预约</div> </div> </div> <!-- 每日推荐 --> <div class="section-title">每日推荐</div> <div class="recommend-list"> <div class="card"> <div class="card-text"> <div class="card-title">饮食指导</div> <p>坚持每天吃早餐。不吃早餐可能会导致白天食欲增强从而导致...</p> </div> <img class="card-img" src="https://via.placeholder.com/280x200" alt="食物" /> </div> <div class="card"> <div class="card-text"> <div class="card-title">饮食指导</div> <p>坚持每天吃早餐。不吃早餐可能会导致白天食欲增强从而导致...</p> </div> <img class="card-img" src="https://via.placeholder.com/280x200" alt="食物" /> </div> </div> <!-- 精选食谱 --> <div class="section-title">精选食谱</div> <div class="selected-list"> <div class="card"> <div class="card-text"> <div class="card-title">饮食指导</div> <p>坚持每天吃早餐。不吃早餐可能会导致白天食欲增强从而导致...</p> </div> <img class="card-img" src="https://via.placeholder.com/280x200" alt="食物" /> </div> </div> <!-- 底部 Tab --> <div class="footer-nav"> <div class="footer-item footer-active"> <svg class="footer-icon" viewBox="0 0 24 24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg> <div class="footer-text">首页</div> </div> <div class="footer-item"> <svg class="footer-icon" viewBox="0 0 24 24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg> <div class="footer-text">发现</div> </div> <div class="footer-item"> <svg class="footer-icon" viewBox="0 0 24 24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg> <div class="footer-text">消息</div> </div> <div class="footer-item"> <svg class="footer-icon" viewBox="0 0 24 24"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg> <div class="footer-text">我的</div> </div> </div> </body></html>检查代码 让排版更美观
最新发布
11-25
<style scoped> :root { --primary-color: #4299e1; --dark-bg: rgba(16, 16, 16, 0.9); --element-bg: rgba(32, 32, 32, 0.8); --text-primary: #e0e0e0; --text-secondary: #a0aec0; } .avatar-uploader ::v-deep .el-upload { border: 1px dashed #d9d9d9; border-radius: 6px; cursor: pointer; position: relative; overflow: hidden; width: 100%; height: 200px; } .avatar-uploader .el-upload:hover { border-color: #409EFF; } .avatar-uploader-icon { font-size: 28px; color: #8c939d; width: 100%; height: 200px; line-height: 200px; text-align: center; } .avatar { width: 100%; height: 200px; display: block; object-fit: cover; } /* 暗黑主题容器 */ .app-container { background: rgba(0, 0, 0, 0.9) url('https://class426-wuxinzhang.oss-cn-beijing.aliyuncs.com/1.jpg') center/cover fixed; /* 替换为你的背景图URL */ min-height: 100vh; color: #e0e0e0; } /* 全局覆盖ElementUI组件样式 */ ::v-deep .el-table { background: rgba(16, 16, 16, 0.8); color: #c0c0c0; } ::v-deep .el-table th { background: #1a1a1a !important; color: #40a0ff; /* 表头文字使用主题蓝 */ } ::v-deep .el-table tr { background: rgba(32, 32, 32, 0.8); } ::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td { background: rgba(64, 64, 64, 0.5) !important; } /* 按钮统一风格 */ ::v-deep .el-button { border-radius: 20px; padding: 10px 25px; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); } /* 主按钮 */ ::v-deep .el-button--primary { background: linear-gradient(135deg, #2a4365 0%, #1a365d 100%); border-color: #2c5282; } ::v-deep .el-button--primary:hover { transform: translateY(-2px); box-shadow: 0 4px 15px rgba(42, 67, 101, 0.5); } /* 危险按钮 */ ::v-deep .el-button--danger { background: linear-gradient(135deg, #63171b 0%, #4a0e11 100%); border-color: #742a2a; } /* 操作列微型按钮 */ ::v-deep .el-button--text { color: #63b3ed !important; font-size: 12px; padding: 2px 8px; } /* 输入框与选择器 */ ::v-deep .el-input__inner, ::v-deep .el-select .el-input__inner { background: rgba(64, 64, 64, 0.5); border: 1px solid #4a5568; color: #e2e8f0; } ::v-deep .el-input__inner::placeholder { color: #718096; } /* 上传组件样式 */ .avatar-uploader ::v-deep .el-upload { border: 2px dashed #4a5568; background: rgba(45, 55, 72, 0.5); } .avatar-uploader ::v-deep .el-upload:hover { border-color: #4299e1; } .avatar-uploader-icon { color: #718096; } /* 弹窗背景 */ ::v-deep .el-dialog { background: rgba(26, 32, 44, 0.95); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); } ::v-deep .el-dialog__title { color: #63b3ed; } /* 分页器 */ ::v-deep .el-pagination { color: #a0aec0; } ::v-deep .el-pager li { background: rgba(45, 55, 72, 0.8); } ::v-deep .el-pagination button:hover { color: #63b3ed !important; } </style> 这是一段样式的代码,请帮我修改成淡色系并且添加你认为喊看的背景颜色和风格,帮我生成完整的style标签中的代码
05-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值