我可以将图像设置为我的TableView背景,但图像位于视图的中心 如何将图像设置为顶部?
我正在使用staticTableView
private WebSocket mConnection;
private WebSocketConnectCallback mSocketCallback = new WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, WebSocket webSocket) {
...
webSocket.setClosedCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
Log.d("websocket", "WebSocket closed");
if (ex != null && ex.getMessage() != null) {
Log.e("websocket", "WebSocket closed exception: " + ex.getMessage());
}
disconnect();
}
});
}
};
private void disconnect() {
mPingHandler.removeCallbacks(pingRunnable);
if (mConnection != null) {
mConnection.close();
mConnection = null;
}
}
答案 0 :(得分:0)
如果您使用静态表并且没有机会更改它,您可能需要采取这样的方法:
override func viewDidLoad() {
super.viewDidLoad()
//Create the UIImage
let image = UIImage(named: "testing")
//Create a container view that will take all of the tableView space and contain the imageView on top
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: self.view.bounds.width, height: self.view.bounds.height))
//Create the UIImageView that will be on top of our table
let imageView = UIImageView(frame: CGRect(x: 0.0, y: 0.0, width: self.view.bounds.width, height: image!.size.height))
//Set the image
imageView.image = image
//Clips to bounds so the image doesnt go over the image size
imageView.clipsToBounds = true
//Scale aspect fill so the image doesn't break the aspect ratio to fill in the header (it will zoom)
imageView.contentMode = UIViewContentMode.ScaleAspectFit
containerView.addSubview(imageView)
self.tableView.backgroundView = containerView
}
根据需要使单元格或标题透明。我不知道您的UI应该如何工作。此方法不会滚动imageView,但您可以在scrollView委托方法中执行此操作。如果你需要滚动我会告诉我,我会帮你解决