iOS 小程序自定义启动加载页

当启动小程序时,如小程序未下载到设备,小程序容器会启动加载页(如下图)提示用户等待,待小程序安装到设备上,加载页关闭并跳转至小程序。

启动加载项

实现自定义加载页

对于 iOS 小程序,mPaaS 支持开发者自定义加载页内容,您可按照以下步骤进行配置:

  1. 继承 APBaseLoadingView 的子类,自定义加载页 View 子类,您可以在子类中修改页面 view 的样式。

    subclass

    代码示例如下:

    1. @interface MPBaseLoadingView : APBaseLoadingView
    2. @end
    3. @implementation MPBaseLoadingView
    4. - (instancetype)init
    5. {
    6. self = [super init];
    7. if (self) {
    8. self.backgroundColor = [UIColor grayColor];
    9. self.titleLabel.backgroundColor = [UIColor redColor];
    10. self.titleLabel.font = [UIFont boldSystemFontOfSize:8];
    11. self.iconImageView.backgroundColor = [UIColor blueColor];
    12. self.pageControl.backgroundColor = [UIColor orangeColor];
    13. }
    14. return self;
    15. }
    16. - (void)layoutSubviews
    17. {
    18. [super layoutSubviews];
    19. // 调整 view 的位置
    20. CGSize size = self.bounds.size;
    21. CGRect frame = CGRectMake((size.width - 80)/2, 0, 80, 80);
    22. self.iconImageView.frame = frame;
    23. frame = CGRectMake(15, CGRectGetMaxY(self.iconImageView.frame) + 6, size.width - 30, 22);
    24. self.titleLabel.frame = frame;
    25. frame = CGRectMake((size.width-40)/2, CGRectGetMaxY(self.titleLabel.frame) + 21, 40, 20);
    26. self.pageControl.frame = frame;
    27. }
    28. @end
  2. DTFrameworkInterface 类的 category 中,重写 baseloadViewClass 方法,返回自定义的加载页 View 类名。

    1. - (NSString *)baseloadViewClass
    2. {
    3. return @"MPBaseLoadingView";
    4. }
阿里云首页 移动开发平台 mPaaS 相关技术圈