Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 80eb68d7
由
cgx
编写于
2022-10-28 11:46:16 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
优化输入框占位文字显示问题
1 个父辈
6e0740a2
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
40 行增加
和
33 行删除
DreamSleep/DreamSleep/Class/CommunityModule/DynamicPublish/DynamicView.m
DreamSleep/DreamSleep/Class/CommunityModule/View/MKTextView/MKPPlaceholderTextView.h
DreamSleep/DreamSleep/Class/CommunityModule/View/MKTextView/MKPPlaceholderTextView.m
DreamSleep/DreamSleep/Class/CommunityModule/DynamicPublish/DynamicView.m
查看文件 @
80eb68d
...
@@ -174,7 +174,7 @@
...
@@ -174,7 +174,7 @@
_textView
.
delegate
=
self
;
_textView
.
delegate
=
self
;
[
_textView
cornerRadius
:
12
];
[
_textView
cornerRadius
:
12
];
_textView
.
textContainerInset
=
UIEdgeInsetsMake
(
15
,
8
,
40
,
8
);
_textView
.
textContainerInset
=
UIEdgeInsetsMake
(
15
,
8
,
40
,
8
);
_textView
.
placeholder
=
@"请文明发言,不可涉及黄、赌、毒、国家政治相关动态!"
;
_textView
.
placeholder
=
@"请文明发言,不可
发布
涉及黄、赌、毒、国家政治相关动态!"
;
_textView
.
placeholderLabel
.
dk_textColorPicker
=
DKColorPickerWithColors
(
ColorFromHexA
(
0x777777
,
.
3
),
ColorFromHexA
(
0xFFFFFF
,
.
3
),
DSWhite
);
_textView
.
placeholderLabel
.
dk_textColorPicker
=
DKColorPickerWithColors
(
ColorFromHexA
(
0x777777
,
.
3
),
ColorFromHexA
(
0xFFFFFF
,
.
3
),
DSWhite
);
}
}
return
_textView
;
return
_textView
;
...
...
DreamSleep/DreamSleep/Class/CommunityModule/View/MKTextView/MKPPlaceholderTextView.h
查看文件 @
80eb68d
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
@interface
MKPPlaceholderTextView
:
UITextView
@interface
MKPPlaceholderTextView
:
UITextView
/** 占位文字label */
/** 占位文字label */
@property
(
nonatomic
,
weak
)
UILabel
*
placeholderLabel
;
@property
(
nonatomic
,
strong
)
UILabel
*
placeholderLabel
;
/** 占位文字 */
/** 占位文字 */
@property
(
nonatomic
,
copy
)
NSString
*
placeholder
;
@property
(
nonatomic
,
copy
)
NSString
*
placeholder
;
...
...
DreamSleep/DreamSleep/Class/CommunityModule/View/MKTextView/MKPPlaceholderTextView.m
查看文件 @
80eb68d
...
@@ -9,34 +9,25 @@
...
@@ -9,34 +9,25 @@
#import "MKPPlaceholderTextView.h"
#import "MKPPlaceholderTextView.h"
@interface
MKPPlaceholderTextView
()
@interface
MKPPlaceholderTextView
()
@property
(
nonatomic
,
strong
)
UIView
*
tmpView
;
@end
@end
@implementation
MKPPlaceholderTextView
@implementation
MKPPlaceholderTextView
-
(
UILabel
*
)
placeholderLabel
{
if
(
!
_placeholderLabel
)
{
// 添加一个用来显示占位文字的label
UILabel
*
placeholderLabel
=
[[
UILabel
alloc
]
init
];
placeholderLabel
.
numberOfLines
=
0
;
placeholderLabel
.
x
=
4
;
placeholderLabel
.
y
=
7
;
[
self
addSubview
:
placeholderLabel
];
_placeholderLabel
=
placeholderLabel
;
}
return
_placeholderLabel
;
}
-
(
instancetype
)
initWithFrame
:(
CGRect
)
frame
{
-
(
instancetype
)
initWithFrame
:(
CGRect
)
frame
{
if
(
self
=
[
super
initWithFrame
:
frame
])
{
if
(
self
=
[
super
initWithFrame
:
frame
])
{
// 垂直方向上永远有弹簧效果
//self.alwaysBounceVertical = YES;
// 默认字体
// 默认字体
self
.
font
=
[
UIFont
systemFontOfSize
:
15
];
self
.
font
=
[
UIFont
systemFontOfSize
:
15
];
// 默认的占位文字颜色
// 默认的占位文字颜色
self
.
placeholderColor
=
ColorFromHexA
(
0xFFFFFF
,
.
6
);
self
.
placeholderColor
=
ColorFromHexA
(
0xFFFFFF
,
.
6
);
[
self
addSubview
:
self
.
tmpView
];
[
self
.
tmpView
addSubview
:
self
.
placeholderLabel
];
[
self
.
tmpView
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
edges
.
equalTo
(
self
);
make
.
size
.
equalTo
(
self
);
}];
// 监听文字改变
// 监听文字改变
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
textDidChange
)
name
:
UITextViewTextDidChangeNotification
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
textDidChange
)
name
:
UITextViewTextDidChangeNotification
object
:
nil
];
}
}
...
@@ -47,6 +38,18 @@
...
@@ -47,6 +38,18 @@
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
];
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
];
}
}
-
(
void
)
layoutSubviews
{
[
self
.
placeholderLabel
sizeToFit
];
UIEdgeInsets
insets
=
self
.
textContainerInset
;
CGFloat
leftMargin
=
insets
.
left
==
0
?
8
:
insets
.
left
+
3
;
CGFloat
topMargin
=
insets
.
top
==
0
?
8
:
insets
.
top
;
[
self
.
placeholderLabel
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
left
.
equalTo
(
self
.
tmpView
).
offset
(
leftMargin
);
make
.
top
.
equalTo
(
self
.
tmpView
).
offset
(
topMargin
);
make
.
right
.
equalTo
(
self
.
tmpView
).
offset
(
-
leftMargin
);
}];
}
/**
/**
* 监听文字改变
* 监听文字改变
*/
*/
...
@@ -55,19 +58,6 @@
...
@@ -55,19 +58,6 @@
self
.
placeholderLabel
.
hidden
=
self
.
hasText
;
self
.
placeholderLabel
.
hidden
=
self
.
hasText
;
}
}
/**
* 更新占位文字的尺寸
*/
-
(
void
)
layoutSubviews
{
[
super
layoutSubviews
];
UIEdgeInsets
insets
=
self
.
textContainerInset
;
self
.
placeholderLabel
.
x
=
insets
.
left
==
0
?
8
:
insets
.
left
+
3
;
self
.
placeholderLabel
.
y
=
insets
.
top
==
0
?
8
:
insets
.
top
;
self
.
placeholderLabel
.
width
=
self
.
width
-
2
*
self
.
placeholderLabel
.
x
;
[
self
.
placeholderLabel
sizeToFit
];
}
#pragma mark - 重写setter
#pragma mark - 重写setter
-
(
void
)
setPlaceholderColor
:
(
UIColor
*
)
placeholderColor
{
-
(
void
)
setPlaceholderColor
:
(
UIColor
*
)
placeholderColor
{
_placeholderColor
=
placeholderColor
;
_placeholderColor
=
placeholderColor
;
...
@@ -100,4 +90,21 @@
...
@@ -100,4 +90,21 @@
[
self
textDidChange
];
[
self
textDidChange
];
}
}
#pragma mark - lazy
-
(
UIView
*
)
tmpView
{
if
(
!
_tmpView
)
{
_tmpView
=
[
UIView
new
];
_tmpView
.
userInteractionEnabled
=
NO
;
}
return
_tmpView
;
}
-
(
UILabel
*
)
placeholderLabel
{
if
(
!
_placeholderLabel
)
{
_placeholderLabel
=
[[
UILabel
alloc
]
init
];
_placeholderLabel
.
numberOfLines
=
0
;
}
return
_placeholderLabel
;
}
@end
@end
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论