【发布时间】:2021-03-19 21:20:24
【问题描述】:
我正在开发一个颤振插件。我与 Swift 一起使用的库有一个 UITextField 子类。我无法在屏幕上显示这个子类。只有当我使用 UITextField 对象尝试它时,它才会出现在屏幕上。如何在屏幕上显示此对象?
我的代码
dnmTextField = DnmTextField(frame: rc)
dnmTextField?.autoresizingMask = .flexibleWidth
dnmTextField?.layer.borderWidth = 1.0
dnmTextField?.layer.borderColor = UIColor.black.cgColor
dnmTextField?.clipsToBounds = true
dnmTextField?.keyboardType = UIKeyboardType.numberPad
dnmTextField?.textAlignment = .center
dnmTextField?.backgroundColor = UIColor.black
dnmTextField?.placeholder = (args!["placeholder"] as! String)
let presentedViewController = viewController?.presentedViewController
let currentViewController: UIViewController? = (presentedViewController ?? viewController)
currentViewController?.view.addSubview(dnmTextField!)
自定义 UITextField 子类参考
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@protocol DnmTextFieldDelegate <NSObject>
@optional
- (void) dnmTextFieldShouldBeginEditing:(NSInteger)typeId;
- (void) dnmTextFieldDidBeginEditing:(NSInteger)typeId;
- (void) dnmTextFieldDidEndEditing:(NSInteger)typeId;
- (void) dnmTextFieldEditingChange:(NSInteger)typeId;
- (void) dnmTextFieldDidClear:(NSInteger)typeId;
@end
@interface DnmTextField : UITextField
- (void)setSystemId:(NSString*)systemId;
- (void)setMaxLength:(NSUInteger)maxLength;
- (void)setType:(NSInteger)typeId;
- (BOOL)isEqualTo:(DnmTextField*)textField2;
- (void)clear;
- (BOOL)validateInput;
- (BOOL)isEmpty;
- (void)setSystemIdforGet:(NSString*)system_Id;
- (void)setTextAlignment:(NSTextAlignment)textAlignment;
- (NSInteger)getTextLength;
@property (nonatomic, weak) id<DnmTextFieldDelegate> dnmDelegate;
@property (nonatomic, assign) UIEdgeInsets edgeInsets;
@property (nonatomic, assign) NSDictionary *attrDictionary;
@property (nonatomic) NSUInteger maxLength;
@end
#endif
【问题讨论】:
-
你能展示一下
DnmTextField类的实现吗? -
它是一个静态库,所以我无法查看它的内容。
-
不查看代码我们找不到问题。我建议1)。查看为该库打印的日志。查找该类的任何异常。 2.捕获视图层次结构,并检查是否添加了视图。如果添加了什么是视图框架。
-
你能提供一个有这个问题的示例项目吗?捕获视图层次结构说明了什么?即使外部代码相同,子类可能会覆盖布局方法,这将导致大小为零
标签: ios objective-c swift flutter flutter-plugin