小编use*_*551的帖子

导航栏中的ios标题和副标题居中

我试图在导航栏中有两个UILabel而不是一个.

我按照此链接获取有关如何执行此操作的信息: 导航栏中的iPhone标题和副标题

它运作良好,但我不能让我的文本正确居中.它在按钮之间居中,但默认的标题行为是在正确的时间内居中.

在此输入图像描述

我看了一下,同样的问题,但没有回答: UINavigationBar TitleView带副标题

我错过了什么?这是我的代码:

CGRect headerTitleSubtitleFrame = CGRectMake(0, 0, 200, 44);
UIView* _headerTitleSubtitleView = [[UILabel alloc] initWithFrame:headerTitleSubtitleFrame];
_headerTitleSubtitleView.backgroundColor = [UIColor clearColor];
_headerTitleSubtitleView.autoresizesSubviews = NO;

CGRect titleFrame = CGRectMake(0, 2, 200, 24);
UILabel *titleView = [[UILabel alloc] initWithFrame:titleFrame];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20];
titleView.textAlignment = NSTextAlignmentCenter;
titleView.textColor = [UIColor whiteColor];
titleView.shadowColor = [UIColor darkGrayColor];
titleView.shadowOffset = CGSizeMake(0, -1);
titleView.text = @"Title";
titleView.adjustsFontSizeToFitWidth = YES;
[_headerTitleSubtitleView addSubview:titleView];

CGRect subtitleFrame = CGRectMake(0, 24, 200, 44-24);
UILabel …
Run Code Online (Sandbox Code Playgroud)

center title uinavigationbar subtitle ios

5
推荐指数
1
解决办法
1万
查看次数

返回重定向响应而不是预期的叶视图

我有一个路由处理程序,它为我的登录页面返回一个 Future,定义如下:

func boot(router: Router) throws {
    let authSessionRoutes = router.grouped(User.authSessionsMiddleware())
    authSessionRoutes.get("/login", use: loginHandler)
}

func loginHandler(_ req: Request) throws -> Future<View> {
    return try req.view().render("loginPage")
}
Run Code Online (Sandbox Code Playgroud)

当用户未连接时,这很有效,但我想添加逻辑,以便任何尝试访问此页面的经过身份验证的用户都将被重定向到他们的主页。

这是我尝试过的:

func loginHandler(_ req: Request) throws -> Future<View> {

    if let _ = try req.authenticated(User.self) {
        return req.redirect(to: "/") <<< Cannot convert return expression of type 'Response' to return type 'EventLoopFuture<View>'
    }

    return try req.view().render("loginPage")
}
Run Code Online (Sandbox Code Playgroud)

这告诉我,由于我的 loginHandler 应该返回 a Future<View>,因此返回 aResponse不符合方法的定义。

处理这种情况的最佳方法是什么?

编辑 :

谢谢你的回答 !我的最终代码如下所示:

func loginHandler(_ …
Run Code Online (Sandbox Code Playgroud)

routing swift vapor server-side-swift

5
推荐指数
1
解决办法
802
查看次数