相关疑难解决方法(0)

使用Objective-C中的类别覆盖方法

我可以使用类类别来覆盖已使用类别实现的方法吗?像这样:

1)原始方法

-(BOOL) method {
  return true;
}
Run Code Online (Sandbox Code Playgroud)

2)覆盖方法

-(BOOL) method {
  NSLog(@"error?"); 
  return true; 
}
Run Code Online (Sandbox Code Playgroud)

这会起作用,还是非法的?

objective-c categories

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

view.traitCollection.horizo​​ntalSizeClass在viewDidLoad中返回undefined(0)

我在UIPageViewController中使用UITextView,我想根据设备的大小类确定字体大小.

页面视图的第一张幻灯片加载在ViewDidLoad中,如so(viewControllerAtIndex(0)):

override func viewDidLoad() {
    super.viewDidLoad()

    //Some unrelated code here

    // Page View Controller for Questions Slider
    questionPageVC = storyboard?.instantiateViewControllerWithIdentifier("QuestionPageView") as? UIPageViewController
    questionPageVC!.dataSource = self;
    questionPageVC!.delegate = self;

    let startingViewController : QuestionContentViewController = viewControllerAtIndex(0) as QuestionContentViewController
    var viewControllers = [startingViewController]

    questionPageVC!.setViewControllers(viewControllers, direction: .Forward, animated: true, completion: nil)

    let sliderHeight = view.frame.size.height * 0.5
    questionPageVC!.view.frame = CGRectMake(20, 70,
     view.frame.size.width-40, sliderHeight)

    addChildViewController(questionPageVC!)
    view.addSubview(questionPageVC!.view!)
    questionPageVC?.didMoveToParentViewController(self)

    var pageControl : UIPageControl = UIPageControl.appearance()
    pageControl.pageIndicatorTintColor = UIColor.lightGrayColor()
    pageControl.currentPageIndicatorTintColor = UIColor.blackColor()
    pageControl.backgroundColor = UIColor.whiteColor() …
Run Code Online (Sandbox Code Playgroud)

ios swift

19
推荐指数
2
解决办法
6314
查看次数

iOS中具有大小类的自定义字体

我正在尝试使用大小类为iphone和ipad布局添加2种不同的字体大小.它使用默认的系统字体很酷,但不能使用自定义字体(我在我的项目中使用PragmataPro).如果我为wR hR添加第二个大小,那么字体在界面构建器中看起来正确(我甚至检查过xml)但是在模拟器和设备上它变成了System而不是PragmataPro.但是,如果我删除wR hR(或我正在使用的其他尺寸的任何布局),那么字体显示正确.不知道如何解决这个问题?谢谢!

size fonts class ios xcode6

7
推荐指数
1
解决办法
1586
查看次数

Xcode 6中不同设备的字体大小不同

我想在不同的设备上使用相同的文本.我正在使用通用故事板,但我找不到任何字体大小的限制.我知道您可以在新布局的不同设备上使用不同的文本字段,但我需要在代码中添加一些逻辑.我想使用相同的文本字段.

xcode ios swift xcode6

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

当应用程序进入后台状态时,layoutSubviews 被重复调用

我希望标签的字体大小与屏幕大小成正比。我已经对这个UILabel类进行了子类化来完成这个:

@IBDesignable class MyCustomLabel: UILabel {
    override func layoutSubviews() {
        super.layoutSubviews()
        self.font = UIFont(name: "myFontName", size: (self.font?.pointSize)!)
        self.adjustsFontSizeToFitWidth = true
    }
}
Run Code Online (Sandbox Code Playgroud)

标签(与附加到它们的超级视图约束成比例的宽度)在应用程序首次启动时正确调整大小,但是当它进入后台状态时layoutSubviews会被重复调用。该应用程序不再响应用户的输入并不断为字体分配字体大小。

为什么会这样?

ios autolayout swift

4
推荐指数
1
解决办法
1183
查看次数

标签 统计

ios ×4

swift ×3

xcode6 ×2

autolayout ×1

categories ×1

class ×1

fonts ×1

objective-c ×1

size ×1

xcode ×1