Use the same code in the viewDidLayoutSubviews or viewDidAppear . In fact, according to the life cycle of the view, the methods are executed as follows: init , loadView , viewDidLoad , viewWillAppear , viewWillLayoutSubViews , then the autodetection restrictions are applied (the number of autodetection restrictions you have, this layout method is called), then viewDidLayoutSubviews and finally viewDidAppear .
From your question, it looks like you put your code in any of the methods before the autodetection restrictions are applied. This is why you are not getting the right viewing width, and it turns into a diamond instead of a circle.
source share