gpt4 book ai didi

ios - 自定义 `UITextField` 子类没有出现在屏幕上

转载 作者:行者123 更新时间:2023-12-04 08:27:14 24 4
gpt4 key购买 nike

我正在开发一个 flutter 插件。我与 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

最佳答案

目前最可能的原因是您将文本字段框架设置为零。 View 位于 (0, 0) 的屏幕上,其大小为 (0, 0) - 因此您不会看到文本字段。
为了使测试更容易,将背景颜色设置为显眼的颜色:

dnmTextField.backgroundColor = .red
并创建具有非零尺寸框架的 View :
dnmTextField = DnmTextField(frame: CGRect(x: 50, y: 50, width: 100, height: 50))

关于ios - 自定义 `UITextField` 子类没有出现在屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65200866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com