我正在为我的项目使用Ionic,我遇到了Tab bar的问题。我很想知道如何在离子标签栏上设置图像而不是图标这样根据各种设备尺寸重新调整图像大小。
答案 0 :(得分:0)
我的tabs.html看起来像这样......我非常简单
<ion-tabs class="tabs-icon-only tabs-color-active-positive">
<!-- Profile Tab -->
<ion-tab title="profile" icon-off="profile" icon-on="profile" href="#/tab/profile">
<ion-nav-view name="tab-profile"></ion-nav-view>
</ion-tab>
<!-- offer Tab -->
<ion-tab title="offers" icon-off="offers" icon-on="offers" href="#/tab/offers">
<ion-nav-view name="tab-offers"></ion-nav-view>
</ion-tab>
<!-- inbox Tab -->
<ion-tab title="inbox" icon-off="inbox" icon-on="inbox" href="#/tab/inbox">
<ion-nav-view name="tab-inbox"></ion-nav-view>
</ion-tab>
<!-- share Tab -->
<ion-tab title="share" icon-off="share" icon-on="share" href="#/tab/share">
<ion-nav-view name="tab-share"></ion-nav-view>
</ion-tab>
<!-- settings Tab -->
<ion-tab title="settings" icon-off="settings" icon-on="settings" href="#/tab/settings">
<ion-nav-view name="tab-settings"></ion-nav-view>
</ion-tab>
</ion-tabs>
和相关的CSS是
.tabs .tab-item .icon.profile {
background-repeat: no-repeat;
background-position:50%;
height: 100%;
background-image: url('../img/profile.png');
background-size:cover;
}
.tabs .tab-item .icon.offers {
background-repeat: no-repeat;
background-position: 50%;
height: 100%;
background-image: url('../img/offer.png');
background-size:cover;
}
.tabs .tab-item .icon.inbox {
background-repeat: no-repeat;
background-position: 50%;
height: 100%;
background-image: url('../img/inbox.png');
background-size:cover;
}
.tabs .tab-item .icon.share {
background-repeat: no-repeat;
background-position: 50%;
height: 100%;
background-image: url('../img/share.png');
background-size:cover;
}
.tabs .tab-item .icon.settings {
background-repeat: no-repeat;
background-position: 50%;
height: 100%;
background-image: url('../img/setting.png');
background-size:cover;
}
图像的宽度为126像素,高度为107像素
答案 1 :(得分:0)
发现问题,标签项的最大宽度设置为150px,如果你增加图像应该能够正确缩放,这里是我的代码,我得到它工作即使在非常大的宽度分辨率我也设置了每个标签项的宽度为100%: HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link href="http://code.ionicframework.com/1.0.0/css/ionic.min.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script>
</head>
<body ng-app="app">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Awesome App</h1>
</ion-header-bar>
<ion-content class="padding">
</ion-content>
<ion-tabs class="tabs-icon-only tabs-color-active-positive">
<!-- Profile Tab -->
<ion-tab title="profile" icon-off="profile" icon-on="profile" href="#/tab/profile">
<ion-nav-view name="tab-profile"></ion-nav-view>
</ion-tab>
<!-- offer Tab -->
<ion-tab title="offers" icon-off="offers" icon-on="offers" href="#/tab/offers">
<ion-nav-view name="tab-offers"></ion-nav-view>
</ion-tab>
<!-- inbox Tab -->
<ion-tab title="inbox" icon-off="inbox" icon-on="inbox" href="#/tab/inbox">
<ion-nav-view name="tab-inbox"></ion-nav-view>
</ion-tab>
<!-- share Tab -->
<ion-tab title="share" icon-off="share" icon-on="share" href="#/tab/share">
<ion-nav-view name="tab-share"></ion-nav-view>
</ion-tab>
<!-- settings Tab -->
<ion-tab title="settings" icon-off="settings" icon-on="settings" href="#/tab/settings">
<ion-nav-view name="tab-settings"></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-pane>
</body>
</html>
CSS:
/* Styles here */
.tab-item{
max-width: 300px;
}
.tabs .tab-item .icon.profile {
background-repeat: no-repeat;
background-position:50%;
height: 100%;
width: 100%;
background-image: url('http://dreamatico.com/data_images/car/car-1.jpg');
background-size:cover;
}
.tabs .tab-item .icon.offers {
background-repeat: no-repeat;
background-position: 50%;
height: 100%;
width: 100%;
background-image: url('http://dreamatico.com/data_images/car/car-7.jpg');
background-size:cover;
}
.tabs .tab-item .icon.inbox {
background-repeat: no-repeat;
background-position: 50%;
height: 100%;
width: 100%;
background-image: url('http://dreamatico.com/data_images/car/car-2.jpg');
background-size:cover;
}
.tabs .tab-item .icon.share {
background-repeat: no-repeat;
background-position: 50%;
height: 100%;
width: 100%;
background-image: url('http://dreamatico.com/data_images/car/car-4.jpg');
background-size:cover;
}
.tabs .tab-item .icon.settings {
background-repeat: no-repeat;
background-position: 50%;
height: 100%;
width: 100%;
background-image: url('http://dreamatico.com/data_images/car/car-5.jpg');
background-size:cover;
}