简体   繁体   English

在视图中将Stripe PaymentKit信用卡文本字段居中

[英]Centering the Stripe PaymentKit credit card textfield in the view

I am using code from Stripe PaymentKit. 我正在使用Stripe PaymentKit中的代码。 They've provided the code for the PaymentViewController and I want the textfield to be centered in the view but I can't figure out how. 他们提供了PaymentViewController的代码,我希望文本字段在视图中居中,但我不知道如何。 I can change the position and width/height easily but I want it to be horizontally centered... Any ideas? 我可以轻松更改位置和宽度/高度,但我希望它水平居中...有什么想法吗?

I found a workaround by modifying the x coordinate: 我通过修改x坐标找到了一种解决方法:

float X_Co = (self.view.frame.size.width - 290)/2;
self.paymentView = [[PTKView alloc] initWithFrame:CGRectMake(X_Co, 240, 290, 55)];

I placed an empty UIView inside my presenting view controller in Storyboard, set its width to be 290 and the height to be 55 (the width and height of the PTKView), set it to align center X with the Superview, and created a referencing outlet in my view controller named paymentViewArea . 我在演示图板的演示视图控制器中放置了一个空的UIView,将其宽度设置为290,将高度设置为55(PTKView的宽度和高度),将其设置为使X中心与Superview对齐,并创建了参考出口在我的视图控制器中,命名为paymentViewArea

Then I loaded the PTKView into that view 然后我将PTKView加载到该视图中

self.paymentView = PTKView(frame: CGRectMake(0, 0, 290, 55))
self.paymentViewArea.addSubview(self.paymentView)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM