2014-09-23 92 views
30

當我做任何iOS 8今日擴展時,即使在界面生成器我在左邊放置一個標籤在x = 0左邊約有48px左側有一個空白空間。適合寬度在iOS 8今日擴展


on xcode on the simulator


我已經看到了一些應用程序,但是,使用全寬度小部件。


other apps


我如何能實現類似的東西?

謝謝!


UPDATE:解決

我把這裏的樣本代碼,因爲我想這將是有用的人。正如@利瑪竇 - lallone建議,要做到這一點,正確的做法是:

-(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMa‌​rginInsets{ 
return UIEdgeInsetsZero; 
} 

回答

37
從文檔

直:

使用Xcode今天模板創建的今天,控件包括標準自動 佈局限制邊緣插入。要爲您的計算獲取插值 ,請實施 widgetMarginInsetsForProposedMarginInsets:方法。

來源:App Extension Programming Guide - Today

+5

謝謝,正如你所建議的,我添加了這段代碼,問題解決了! - (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets {return UIEdgeInsetsZero;} – 2014-09-23 12:50:38

+1

您的鏈接已死亡。拿這個[NotificationCenter.html](https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/NotificationCenter.html#//apple_ref/doc/uid/TP40014214-CH11-SW5) – Felix 2014-09-23 19:54:38

+0

謝謝@Felix,當我發佈它時,它很好!更新。 – 2014-09-24 17:02:24

23

我可以補充SWIFT版本

func widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets { 
    return UIEdgeInsetsZero 
} 

爲OC

-(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets { 
    return UIEdgeInsetsZero 
} 

希望它可以幫助別人。

+0

這非常有幫助,謝謝。 – whenov 2015-06-06 16:32:17

+0

這解決了它對我來說。 – DeyaEldeen 2017-01-24 09:13:42