【问题标题】:Is there way to connect css and UI custom class有没有办法连接css和UI自定义类
【发布时间】:2012-08-21 09:16:57
【问题描述】:

非常感兴趣的是有什么方法可以连接 CSS 样式和 UI 自定义类。例如创建继承 UIButton 类的类并向它们添加 CSS 样式。可能吗?

编辑 我的CSS:

.button {
   border: 3px solid #0a3c59;
   background: #3e779d;
   background: -webkit-gradient(linear, left top, left bottom, from(#65a9d7), to(#3e779d));
   background: -webkit-linear-gradient(top, #65a9d7, #3e779d);
   background: -moz-linear-gradient(top, #65a9d7, #3e779d);
   background: -ms-linear-gradient(top, #65a9d7, #3e779d);
   background: -o-linear-gradient(top, #65a9d7, #3e779d);
   background-image: -ms-linear-gradient(top, #65a9d7 0%, #3e779d 100%);
   padding: 20px 40px;
   -webkit-border-radius: 10px;
   -moz-border-radius: 10px;
   border-radius: 10px;
   -webkit-box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(255,255,255,0.4) 0 1px 0;
   -moz-box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(255,255,255,0.4) 0 1px 0;
   box-shadow: rgba(255,255,255,0.4) 0 1px 0, inset rgba(255,255,255,0.4) 0 1px 0;
   text-shadow: #7ea4bd 0 1px 0;
   color: #06426c;
   font-size: 9px;
   font-family: helvetica, serif;
   text-decoration: none;
   vertical-align: middle;
}
.button:hover {
   border: 3px solid #0a3c59;
   text-shadow: #1e4158 0 1px 0;
   background: #3e779d;
   background: -webkit-gradient(linear, left top, left bottom, from(#65a9d7), to(#3e779d));
   background: -webkit-linear-gradient(top, #65a9d7, #3e779d);
   background: -moz-linear-gradient(top, #65a9d7, #3e779d);
   background: -ms-linear-gradient(top, #65a9d7, #3e779d);
   background: -o-linear-gradient(top, #65a9d7, #3e779d);
   background-image: -ms-linear-gradient(top, #65a9d7 0%, #3e779d 100%);
   color: #fff;
}
.button:active {
  text-shadow: #1e4158 0 1px 0;
  border: 3px solid #0a3c59;
  background: #65a9d7;
  background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#3e779d));
  background: -webkit-linear-gradient(top, #3e779d, #65a9d7);
  background: -moz-linear-gradient(top, #3e779d, #65a9d7);
  background: -ms-linear-gradient(top, #3e779d, #65a9d7);
  background: -o-linear-gradient(top, #3e779d, #65a9d7);
  background-image: -ms-linear-gradient(top, #3e779d 0%, #65a9d7 100%);
  color: #fff;
}

而且我的类继承自 UIButton 类,没有任何其他更改。我只想添加 css 属性。

【问题讨论】:

  • 是的,您可以更改/添加新的 css 属性,但有点复杂,请确保添加后不会影响 JavaScript...
  • 你能给我一些例子或链接到一些教程吗?
  • 检查这个问题,我认为这可能对你有帮助.. stackoverflow.com/questions/1308369/…
  • @K.K 我不知道如何将 css 添加到我的课程中......
  • 你能把你的 CSS 和 UI 自定义类放在这里,以便我解释...

标签: iphone objective-c css ios


【解决方案1】:

它应该可以工作。

<script>
jQuery(function(){
    // add your own class
    jQuery(".button").addClass("ui-button-new-css");

    jQuery(".button.ui-button-new-css").hover(function(){
        jQuery(this).addClass("ui-button-new-css-hover");
    }, function(){
        jQuery(this).removeClass("ui-button-new-css-hover");
    });

    jQuery(".button.ui-button-new-css").focus(function(){
        jQuery(this).addClass("ui-button-new-css-active");
    });

    jQuery(".button.ui-button-new-css").blur(function(){
        jQuery(this).removeClass("ui-button-new-css-active");
    });
});
</script>

<style>
    .button.ui-button-new-css { 
        /* your new css property */
    }
    .button.ui-button-new-css.ui-button-new-css-hover { 
        /* your new hover css property */
    }
    .button.ui-button-new-css.ui-button-new-css-active { 
        /* your new active css property */
    }
</style>

【讨论】:

    猜你喜欢
    • 2021-12-16
    • 1970-01-01
    • 2020-03-23
    • 2019-11-28
    • 1970-01-01
    • 2021-06-17
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多