I'm trying to write a global function that adds an activityIndicator to any view (mostly imageViews though) by calling such function.
The function I have right now is made of:
table
{
width: 100%;
}
td:first-child
{
width: 100px;
}
But I don't get the center of the view for some reason.
I've also tried various solutions around SO and Google, but none worked until now.
Is there any way to get the center point and set the activityIndicator to any UIView?
答案 0 :(得分:14)
我很容易重现你的问题(见我的评论)。 我认为这可能是自动布局的问题。那么你可以使用约束而不是计算位置吗?
<typesThatShouldNotBeExpanded>
希望可以提供帮助。
答案 1 :(得分:12)
斯威夫特3:
activityIndicator.center = CGPoint(x: view.height/2, y: view.width/2)
或者您可以尝试:
activityIndicator.center = view.center
答案 2 :(得分:7)
The private void lstDisplayHardware_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
ListViewItem item = lstDisplayHardware.GetItemAt(e.X, e.Y);
if (item != null)
{
item.Selected = true;
m.MenuItems.Add(new MenuItem(string.Format("Do something to row {0}", item.Position.ToString())));
Clipboard.SetText(item.SubItems[1].Text);
}
m.Show(lstDisplayHardware, new Point(e.X, e.Y));
}
}
property is relative to a view's superview. So if your view's frame is center
, {10, 10, 20, 20}
is going to be center
.
I'm guessing you want to center the {20, 20}
in activityIndicator
.
You can do
view