gpt4 book ai didi

ios - 自定义用户界面 : Popup in iOS Objective-C

转载 作者:行者123 更新时间:2023-11-28 21:15:54 25 4
gpt4 key购买 nike

我想创建一个自定义弹出窗口,并且我想在不使用 UI 拖放的情况下动态生成代码。

View 应该是这样的:

enter image description here

我正在使用以下代码来调用弹出窗口:

 CustomPopUp *cp = [[CustomPopUp alloc]init];
cp.view.frame = CGRectMake(0.0, 0.0, 300, 300);
KLCPopup* popup = [KLCPopup popupWithContentView:cp.view];
[popup show];

自定义弹出代码如下:

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.gaScreenName = @"Login";
if (firstPageLoad) {
return;
}
LinearLayoutPageHeading *heading = [[LinearLayoutPageHeading alloc] initWithText:@"Sign in." maxWidth:[LayoutValues getMaxWidthClipped]];

[self.topContainerContent addObject:heading];
NSString *content = @"New patient? Register here.";

LinearLayoutLinksViewItem *contentItem = [[LinearLayoutLinksViewItem alloc] initLinksViewWithText:content font:[PPFonts genericParagraphFont] maxWidth:[LayoutValues getMaxWidthClipped] links:nil];
[self.topContainerContent addObject:contentItem];
LinearLayoutTextInputAndLabel *emailField = [[LinearLayoutTextInputAndLabel alloc] initWithLabelText:@"EMAIL ADDRESS" maxWidth:[LayoutValues getMaxWidthClipped]];
emailField.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
LinearLayoutButton *continueButton = [[LinearLayoutButton alloc] initWithText:@"SIGN IN" maxWidth:[LayoutValues getMaxWidthClipped] url:nil type:@"primary"];
[self.topContainerContent addObject:continueButton];
LinearLayoutLinksViewItem *noticesPar = [[LinearLayoutLinksViewItem alloc] initLinksViewWithText:@"By clicking Sign In you agree to our Consent to Telehealth, Consent to Request Medical Services, Privacy Policy and Terms of Use." font:[PPFonts signInTermsParagraph] maxWidth:[LayoutValues getMaxWidthClipped] links:nil];
noticesPar.padding = CSLinearLayoutMakePadding(0, noticesPar.padding.left, 10, noticesPar.padding.right);
[self.topContainerContent addObject:noticesPar];
[self renderPageContainers];
firstPageLoad = YES;
}
@end

我正在使用自定义创建的 View Controller ,但出现空白弹出窗口。

有没有办法使用标准的 UIViewController 获得上述布局?我是 iOS 开发的新手,到目前为止还没有动态生成 UI View 。

最佳答案

如果 CustomPopUp 是一个 viewcontroller,你需要用 Storyboard vc 或 xib 来实例化它,像这样:

//For xib:
let a = UIViewController(nibName: "CustomPopUp", bundle: NSBundle.mainBundle()) as! CustomPopUp

//For storyboard
let b = UIStoryboard(name: "main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("CustomPopup") as! CustomPopUp

不太确定你是如何处理这个问题的,但我建议你创建一个自定义 View ,而不是自定义 View Controller ,这样更容易创建和使用

关于ios - 自定义用户界面 : Popup in iOS Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41298100/

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